I am attempting to use the value of a checkbox on a form to control the validation of other fields. But it seems that the value is always false inside the addmethod routine. I must be doing something wrong here but I can't see it.
My addmethod routine is this:
$.validator.addMethod('ValShort', function (value,element)
{
var isChecked = $("value").is(":checked");
alert(isChecked);
return true;
}, 'Please enter a rate for short sessions.');
I set the rule up like this:
rules: {
Test: {ValShort: true}
},
Here is the form:
<form id="Modal-Update-Form" method="post">
<table align="left" width="100%">
<tr><td>test</td><td><input type="checkbox" name="Test" id="Test" /><td></tr>
<tr><td colspan="2" style="padding-bottom:3px;">
<button type="submit" class="Button" name="Update">Update</button>
</td></tr>
</table>
</form>
No matter what I do, the checkbox always shows as false in the alert.
Any ideas on what I am doing wrong, or in how to get the checkbox state inside the addmethod routine?
$("value")selects an element like<value>. There is no such element in your form.Test. You said you wanted to use the rule to control validation of other fields.if (element.checked)Test: required