I have a form with the following two HTML elements:
<input type="text" name="vrm" id="vrm" size="15" maxlength="15" value="" />
<input type="checkbox" id="foreign_registration" name="foreign_registration" value="yes" />
and the following jQuery validation rule (using the validation plugin from here: http://bassistance.de/jquery-plugins/jquery-plugin-validation/):
vrm: {
remote: {
url: "/json/vrm-validate.php",
data: {
foreign_registration: function() {
return $('#foreign_registration').is(':checked');
}
}
}
}
The remote script relies on both fields, as the validation performed on the text field depends on whether the foreign registration is checked or not.
The problem is that if I enter something in the text field and then alter the checkbox, the validation rule isn't re-run. I presume that this is because the validation rule is only attached to the text field, so it will only run whenever that is changed.
Is there a way to say 'these two elements are related, so if either of them change assume that the text field rules should be checked again'? I don't want to attach any validation rules to the checkbox, because it doesn't need to be validated on the client side, and the validation rules performed by the remote script are too complicated to implement in jQuery.