Reputation: 3079
<script type="text/javascript">
//<![CDATA[
function verifyForm()
{
if( document.forms[0].age.value < 18 || >30)
{
alert(" The age input is not valid.");
return false;
}
alert("Form is valid");
return true;
}
//]]>
</script>
</head>
<body>
Enter the following information. Fields denoted with a * are required.
<form action="" method="post" name="aform">
<table>
<tr><td>Enter first name</td><td><input type="text" name="first" /></td></tr>
<tr><td>Enter last name</td><td><input type="text" name="last" />*</td></tr>
<tr><td>Enter your age</td><td><input type="text" name="age" size="5" />*</td></tr>
<tr><td>Enter your sex</td><td><input type="text" name="sex" size="2" />*</td></tr>
<tr><td>Enter your favorite color</td><td><input type="text" name="color" /></td></tr>
<tr><td><input type="button" value="Submit" onclick="verify();" /></td></tr>
</table></form>
I'm trying to verify these forms but whenever I click on the button to verify them nothing happens. Can you help me as to why nothing is happening?
Upvotes: 0
Views: 100
Reputation: 1970
It's probably not working because your function is called verifyForm()
but your button has onclick="verify();"
It should be onclick="verifyForm();"
Javascript console in Chrome:
In Chrome if you click on the wrench > tools > Javascript console
the javascript console will pop up at the bottom of your browser window. If you select the 'console' tab you should get warning and error messages explaining when javascript encounters problems.
Upvotes: 1