JavaScript : Advanced Form Management
Mikael Le Moal
Creating and Presenting the Form
The form we use is made up of two fields. In the first, which is numerical, we intend to receive a numerical value with a
maximum of one decimal place - for instance 12 or 12.2 but not 12.45. This is what we have to enforce with our check.
The second (text) field forbids the use of HTML tags in the input value. The idea here is to verify that the field is correctly
filled in and does not include any unwanted characters.
To create the form we use a conventional HTML code placed between the
<BODY> and
</BODY> tags:
103: <FORM onSubmit="return check(this)">
104: Value:
105: <input type=text name=valeur><BR>
106: Text: <BR>
107: <TEXTAREA cols="50" rows="6" name="texte"></TEXTAREA>
108: <BR>
109: <INPUT type=submit><INPUT type=reset>
110: </FORM>
Before the form is submitted (event
onSubmit), the function
check is executed (line 103) to verify that the form data are valid.
The value this function returns determines whether or not the form is submitted .
true means that data are valid and can be submitted. Otherwise, nothing happens.