I am using this jQuery form validation plugin: http://docs.jquery.com/Plugins/Validation/Methods
I am trying to use the dependancy callback: http://docs.jquery.com/Plugins/Validation/Methods/required#dependency-callback
What I am trying to do is only require "BAR" when "FOO" has a certain value.
Here's a basic example:
<select name="FOO" id="FOO">
<option></option>
<option value="someValue">some Value</option>
</select>
$("form[name=myForm]").validate({
rules: {
FOO: {required: true},
BAR: {
required: function(element) {
return $("#FOO").val() == 'someValue';
},
maxlength: 10
}
}
});
But this is not working. I've also tried using :selected like so:
return $("#FOO :selected").val() == 'someValue';
Can anyone spot what the issue might be?
EDIT = Added the ID of FOO to the select