Open forms.html and save it as jsforms.html.  You probably do not have a script element so add one now.  Inside that add this function:

function adviseUser() {                
    alert('You have just sent this data to the server');                

Add an onsubmit event trigger to the form element opening tag.  That should call the function adviseUser.  Try it and when you submit the form you see a message.  This could be used to check that the form has been correctly filled in before sending it although that requires a slightly different set of code.  Replace the existing function with this one:

function checkUser() {                
        // field is empty so tell them and abort the form submission
        alert('You seem to have forgotten to enter your name');
        return false;

The if statement looks to see if the form field for the user name is empty.  If it is it tells the user.  Then the new bit returns the false value back to the browser so it knows something went wrong.  The browser knows to wait for that reply if you add one thing to the event trigger:

onsubmit="return checkUser();"

Try it and if the message is displayed the form stays.  If the message is not displayed the form is submitted as normal.

You accessed the content of a field using getElementById and value.  That gives you the ability to check the content of any field.  You can check if contents match, exists, don't exist or are too long, too short, the wrong data type and so on.

Other events

There are many form events including: