Quote (Nymphomaniac @ Oct 17 2012 02:59am)
Replace this line:
<form id="form" action="demo_form.asp" name="form" onsubmit="return checkForm(form);" method="post">
with:
<form id="form" action="demo_form.asp" name="form" onsubmit="checkForm(form)">
The "return" thing there has no purpose I think, and the method="post" thing may be what's ruining things.
Additionally, you can probably also replace
<input type="submit" onclick="checkForm(form);" value="Submit"> <br>
with:
<input type="submit" value="Submit"> <br>
The button needs no "onclick" because your form already has an onsubmit.
Edit: You might also have to put form in the function call between apostrophes. Not sure about that though.
The return on the "onsubmit" is required... it needs to pass the return of the function... so if the function returns false, it returns false to the onsubmit (aka don't submit the form)..
You are correct however... the onclick from the submit button needs to be removed, as it will actually run the validation twice.. this way..
your javascript looks great... the only thing i'd change... is that passing form between your checkForm functions is pointless considering it's a global anyway... so...
Code
<form id="form" action="demo_form.asp" name="form" onsubmit="return checkForm();" method="post">
function checkForm()
{
would work the same
THE ONLY problem lies in the HTML... you have TWO forms... delete the one in the middle of the code (not sure how it even got there... and you'll be fine.Code
<form action="">
<select name="type">
<option value="xx"> First time visitor</option>
<option value="xx"> Second time visitor</option>
<option value="xx"> Third time visitor </option>
<option value="xx"> Fourth time visitor </option>
</select>
</form>