Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 281
  • Last Modified:

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
0
dgrafx
Asked:
dgrafx
  • 2
1 Solution
 
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now