Hi I'm using the jQuery Validation plugin, and I'm trying figure out how i can make a name field required if a prefix (Mr, Ms, etc) or a suffix (Jr, Sr, PhD) is selected. This is what I have:
$('#geninfo').validate({
rules:{
firstname: {required: function(element){
return $("#prefix").val() != " ";
}
}
},
messages:{
firstname: 'enter a name'
}
});
Here is the HTML:
<ul>
<li><label for="prefix">Prefix:</label>
<select name="prefix" id="prefix">
<option selected="selected" value=" ">Select One</option>
<option value="ms">Ms</option>
<option value="miss">Miss</option>
<option value="mrs">Mrs</option>
<option value="mr">Mr</option>
<option value="dr">Dr</option>
</select>
</li>
<li><label for="firstname">First Name:</label> <input type="text" name="firstname" id="firstname" /></li>
<li><label for="suffix">Suffix:</label>
<select name="suffix" id="suffix">
<option selected="selected" value=" ">Select One</option>
<option value="jr">Jr</option>
<option value="sr">Sr</option>
<option value="ii">II</option>
</select>
</li></ul>
I can't seem to figure out how i would write the js so that it would account for the prefix || suffix. any clues as to what I am doing wrong? thanks in advance.