mercredi 15 avril 2015

Jquery Validation works on some but not all text inputs

I'm using the jquery validation plugin for the first time...it's working correctly on some of the inputs in my form (simplified below), but not on others. Any idea why? In the example below, the validation works on the first input #planname, but does not work on #q8b.





<form id="form">

<fieldset>
<legend>Plan Name</legend>
<span><input id="planname" type="text" name="planname" value="<?php echo $_SESSION['planname']; ?>" required class="required" /></span>
</fieldset>

<fieldset class="childwrap" id="q8bwrap">
<legend>Do you have an outstanding loan?</legend>
<input id="q8b" type="text" name="q8b" value="<?php if ($_SESSION['q8a'] == "Yes") {echo $_SESSION['q8b']; } ?>"/>%<br/>
</fieldset>

</form>




Included in footer:



<script src="http://ift.tt/1qRgvOJ"></script>

<script src="http://ift.tt/1DTgOfq"></script>

<script src="http://ift.tt/1EjtLA8"></script>




This script works:



<script>
// just for the demos, avoids form submit
jQuery.validator.setDefaults({
debug: true,
success: "valid"
});
$( "#form" ).validate({
rules: {
planname: {
required: true,
max: 23
}
}
});
</script>




This one does not:



<script>
// just for the demos, avoids form submit
jQuery.validator.setDefaults({
debug: true,
success: "valid"
});
$( "#form" ).validate({
rules: {
q8b: {
required: true,
max: 23
}
}
});
</script>


This is just for testing purposes, trying to figure out why it's not working; in the final product, q8b should not be required, but should have a maximum value of 23.


Aucun commentaire:

Enregistrer un commentaire