About this Resource

[?] Compare your HTML and JavaScript in the text box with the model on the right. When you have finished, close this window to return to the main page.

 

<html>
<head>
<link href="../generic/main.css" rel="stylesheet" type="text/css">
<title>Simple validation</title>
<script language="javascript" type="text/javascript">
function validateForm(form) {
if (form.agebox.value =="" || isNaN(form.agebox.value) == true){

alert("please enter your age as a number.");
form.agebox.focus();
form.agebox.value="";
return false;
}

else if (form.agebox.value<18){

alert("You must be 18 or over to complete this questionnaire.");
return false;
}

else {

alert("Welcome to this questionnaire.");
return true;
}

}
</script>
</head>
<body>
<div class="ques">
<form name="egForm2" action="" method="post" onSubmit=" return validateForm(this);">
<p>What is your age?</p>
<p> <input type="text" name="agebox" size="3" maxlength="3" />
<input type="submit" name="submit" value="Submit" />
<input type="reset" name="reset" value="Reset" /></p>
</form></div>
</body>
</html>