Form validation
In the ASP program we often ask users to fill out a form, and then send the button directly sent to us, today this program is to limit the content of the form, and then sent to us.
Just a simple example, I hope to be useful for everyone programming.
HTML form:
<form action= "action.asp" method= "post" name= "MyForm" >
Name and Surname: <br/>
<input type= "text" name= "Nameandsurname" size= "> <br/>
Email: <br/>
<input type= "text" name= "email" size= "> <br/>
Age: <br/>
<input type= "text" name= "Age" size= "3" > <br/>
Gender: <br/>
<select size= "1" name= "gender" >
<option>-Select Gender-</option>
<option value= "Male" >Male</option>
<option value= "Female" >Female</option>
</select> <br/>
<input type= "Submit" value= "Submit" >
</form>
where the check () function is used to detect the contents of the form.
JavaScript functions:
<script language= "JavaScript" type= "Text/javascript" >
function Check () {
var nameandsurname = Document.myform.nameandsurname;
var email = document.myform.email;
var age = Document.myform.age;
var gender = Document.myform.gender;
if (Nameandsurname.value.indexOf ("") = = 1) {
Alert ("Enter your Name and Surname.");
Nameandsurname.focus ();
else if ((Email.value.indexOf ("@") = = 1) | | (Email.value.indexOf (".") = = 1)) {
Alert ("Enter your valid email address.");
Email.focus ();
else if (! (parseint (Age.value) > 0)) {
Alert ("Enter your Age.");
Age.focus ();
else if (Gender.selectedindex = 0) {
Alert ("Select your gender.");
Gender.focus ();
} else {
Document.myform.submit ();
}
}
</SCRIPT>
Put the above JavaScript code in the