JQuery will not validate second form?
Posted: Tue Jun 19, 2012 1:48 pm
Hi Everyone,
I would like to use JQuery to validate my forms. This works well enough if I have a single form on a page, unfortunately, I need to have several forms on one page and have found that the validation quits after the first form. Here's the code:
A couple of things – I switched the order of the forms so that “form2” would be validated first and there was no change in behavior (only the first form in the HTML will be validated). I tried giving both forms “id=form” and I still get the same behavior.
Here's the Jquery code:
And I also tried:
The last script is where both forms had “id=form”. In every case only the first form (in the HTML code) is validated. I also attempted to apply the validation function on a div “id=form” and wrapped the it around both the forms – there was no validation at all. Does anyone know of a way to get the second form to be validated? Thanks in advance for your help!
Cheers,
Rick
I would like to use JQuery to validate my forms. This works well enough if I have a single form on a page, unfortunately, I need to have several forms on one page and have found that the validation quits after the first form. Here's the code:
Code: Select all
<!-- HTML CODE -->
<!-- display first form -->
<div class="formLayout">
<form method="" action="tfc_member.php" id="form1" >
<h4>Login Form</h4>
<label>Username:</label>
<input type="text" name="username" class="required"/><br />
<label>Password:</label>
<input type="password" name="passwd" class="required" /><br /><br />
<label></label><input type="submit" value="Log in"/><br /><br />
</form>
<!-- display second form -->
<form method="" action="" id="form2" >
<h4>Some Other Form</h4>
<label>Account Number:</label>
<input type="text" name="username" class="required"/><br />
<label>Operating District:</label>
<input type="test" name="opDist" class="required" /><br /><br />
<label></label><input type="submit" value="Include This Too"/><br /><br />
</form>
</div>Here's the Jquery code:
Code: Select all
<script>
$(document).ready(function() {
$("#form1, #form2").validate();
}
);
</script>Code: Select all
<script>
$(document).ready(function() {
$("#form").validate();
}
);
</script>Cheers,
Rick