title: jQuery validate - set conditional rules based on user selection
body: <p>Is it possible to easily setup a conditional rule with jQuery validate,</p>
  
  <p>Simply put i'm trying add some logic which says, if checkbox 'A' is ticked - then field 'A' must be completed, if checkbox 'B' completed then fields 'B1' &amp; 'B2' must be completed.</p>
  
  <p>e.g if a checkbox with the name 'paypal' is checked - then the field named 'paypal_address' must be completed.</p>
  
  <p>My existing logic is as follows:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  $(document).ready(function () {
  
  $('#checkout-form').validate({
      rules: {
          first_name: {
              minlength: 2,
              required: true
          },
          last_name: {
              minlength: 2,
              required: true
          },
          address_1: {
              minlength: 2,
              required: true
          },
          address_2: {
              minlength: 2,
              required: true
          },
          post_code: {
              minlength: 2,
              required: true
          },            
          email: {
              required: true,
              email: true
          },
          terms: {
            required: true,
          }
      },
      errorPlacement: function(error, element) { 
        element.addClass('error');
      },        
      highlight: function (element) {
          $(element).addClass('nonvalid')
            .closest('.form-group').removeClass('error');
      },
      success: function (element) {
          //element.addClass('valid')
            //.closest('.form-group').removeClass('error');
            element.remove('error');
      }
  });
  </code></pre>
  
  <p>UPDATE</p>
  
  <p>Using the method below from Rohit i've almost got this working perfectly..
  My form has three checkboxes (only one can be selected)
   1. Paypal
   2. Bank
   3. Check/Cheque</p>
  
  <p>If Paypal is checked (by default it is) then only have the 'paypal_email_address' field required, if Bank is checked then 'account_number' &amp; 'sort_code' fields are required &amp; finally if Cheque is checked the 'check_payable_field' is required.</p>
  
  <p>// i've got this so far
       $( ".paymentMethod" ).on( "click", function() {
        var payment_method = $(this).val();</p>
  
  <pre><code>  if (payment_method == 'paypal') {
      paypal_checked = true;
    } else if (payment_method == 'bank-transfer') {
      bank_checked = true;
      paypal_checked = false;
    } else if (payment_method == 'cheque') {
      cheque_checked = true;
      paypal_checked = false;
    }
  </code></pre>
  
  <p>});</p>