conditional validation using the jquery.validate plugin

Posted on 2012-08-23
Last Modified: 2012-09-07
I have a form with 3 inputs

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.

Question by:dgrafx
    LVL 25

    Accepted Solution

    you can use the depends property. something like this:

       rules: {
           city: {
             depends: function(element) {
               if($("#zip").val() != ""){
                 return false;              
    LVL 24

    Author Comment

    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:

    I will address them both on Monday and sorry again for the delay ...
    LVL 24

    Author Closing Comment

    sorry i forgot about this post ...

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
    I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now