Conditional Validation based on select
Hi there
I'm new to using this plugin, and a particular problem has been driving me nuts!
I want to make a field required based on the value chosen in a drop down list. I've seen a number of different ways of doing this, but can't get any of them to work.
Here's the code....
<select id="ddlNumber" name="ddlNumber">
<option value="">Please Select</option>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
<option value="Other">Other (please specify)</option>
</select>
<input type="text" id="txtOther" value="" />
$(document).ready(function(){
$("#myForm").validate({
rules: {
ddlNumber: "required",
txtOther: {
required: function(element){
return $("#ddlNumber option:selected").val() == "Other";
}
}
},
..........
Help appreciated!