I'm trying to test some input boxes on submit, but its not working for some reason I tried playing with the action and method in the form with no luck. Maybe its my script but i couldn't find where. It should run the script on click of the submit. Thanks
Code:
<!DOCTYPE HTML>
<html>
<head>
<title>Chapter 11</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script type="text/javascript">
function submit(){
if(document.forms[0].visitor_name.value == "" || document.forms[0].visitor_name.value == "Enter your name"){
window.alert("You did not enter your name");
return false;
}else if(document.forms[0].email.value == ""){
window.alert("You did not enter your email address");
return false;
}else if(document.forms[0].pass1.value != document.forms[0].pass2.value ||
document.forms[0].pass1.value == "" || document.forms[0].pass2.value == ""){
window.alert("Your passwords do not match");
}
return true;
}
</script>
</head>
<body>
<h1>Web Site Registration Form</h1>
<form action="" method="post" onsubmit="return submit()">
<h2>Personal Information</h2>
<p>Name
<br>
<br>
<input type="text" value="Enter your name" name="visitor_name"
onclick="if (this.value == 'Enter your name') this.value = '';"
size="50">
<br>
<br>
E-mail address
<br>
<br>
<input type="text" value="Enter your e-mail address" name="email"
onclick="if (this.value == 'Enter your e-mail address') this.value = '';"
size="50">
<br>
</p>
<h2>Security Information</h2>
<p>Enter a password that you can use to manage your subscription online
<br>
<br>
<input type="text" name="pass1" value="" size="50">
<!-- onblur??? -->
<br>
<br>
Type the password again to confirm it
<br>
<br>
<input type="text" name="pass2" value="" size="50">
<br>
<br>
Security question
<br>
<br>
<select name="question">
<option value="mother">What is your mother's maiden name?</option>
<option value="pet">What is the name of pet?</option>
<option value="color">What is your favorite color?</option>
</select>
<br>
<br>
Your answer
<br>
<br>
<input type="text" name="ans" size="50">
<br>
</p>
<h2>Preferences</h2>
<p>Send special offers to my e-mail address
<input type="radio">
<input type="radio">
<br>
<br>
Select areas of interest(select at least one)
<br>
<br>
<input type="checkbox">
<br>
<input type="checkbox">
<br>
<input type="checkbox">
<br>
<input type="checkbox">
<br>
<input type="checkbox">
<br>
<br>
</p>
<p><input type="submit" /></p>
</form>
</body>
</html>
Thanks again.