JavaScript : Checking Form Content
Contents ]
Claude Levior

What About Creating a Form?

Let's imagine you want to offer your visitors an online system so that they can subscribe to your monthly newsletter. You will need a form with two fields for the user's name and mail address. In order to avoid receiving incomplete mail which you cannot process, you will need a control which makes input obligatory in these fields.

Our script is made up of two parts. The first is a function that we will examine later on. Let's begin with our HTML form by placing the following lines in your HTML code where you want the form to appear:

<H2>Receive the site's newsletter!</H2>
<FORM ACTION= "/cgi-bin/mailer" Method=GET
               onSubmit="return Verif(this.form)">
<B>Name: </B>
<INPUT TYPE="text" NAME="nom" SIZE=26 MAXLENGTH=40 >
<BR><BR>
<B>E-mail: </B>
<INPUT TYPE="text" NAME="mail" SIZE=26 MAXLENGTH=40 >
<BR><BR><BR>
<INPUT TYPE="submit" VALUE="Test">
<INPUT TYPE="reset" VALUE="Reset">
</FORM>

Note that we have inserted a JavaScript instruction in the <FORM> tag:

onSubmit="return Verif(this.form)".

This means that the form content, i.e. the data entered by the visitor, will be systematically checked by the Verif function before it is submitted to the server. Let's create this guard function.



1   2   3   4