conditional validation using the jquery.validate plugin

Hello
I have a form with 3 inputs
zipcode
city
state

when the form is submitted
IF zipcode has a value then city & state are NOT required
IF zipcode does NOT have a value then city & state ARE required.

Thanks
LVL 25
dgrafxAsked:
Who is Participating?
 
Kyle HamiltonData ScientistCommented:
you can use the depends property. something like this:

$(".selector").validate({
   rules: {
   
       city: {
         depends: function(element) {
           if($("#zip").val() != ""){
             return false;              
          }
         }
       }
     }
   }
})
0
 
dgrafxAuthor Commented:
Thanks for the comment.
I'm sorry that I didn't have any time to look at it today.

I just asked another question as well:
http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Jquery/Q_27841805.html

I will address them both on Monday and sorry again for the delay ...
0
 
dgrafxAuthor Commented:
sorry i forgot about this post ...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.