0

I am using jQuery validation plugin to validate my html form. I need to create a function to validate my checkbox field. The two options are to be contacted by [phone] or [email]. Once a checkbox is checked, their respective field must then be validated to ensure they enter the phone or email to be contacted by. Thanks for any help!

Here is my checkbox html from within the form:

 <div class="tableRow">
 <p></p>
 <p>
 <input type="checkbox" name="Phone" id="Phone" value="yes"> Phone<br> 
 <input type="checkbox" name="Email" id="Email" value="yes"> E-mail<br>
 </p>
 </div>

Here is my jQuery validation so far for the rest of the form:

     `// Wait for the DOM to be ready
       $(function() {
       // Initialize form validation on the registration form.
       // It has the name attribute "registration"
       $("form[name='helpForm']").validate({
      // Specify validation rules
      rules: {
      // The key name on the left side is the name attribute
      // of an input field. Validation rules are defined
      // on the right side
      name: "required",
      comments: "required",
      },
      // Specify validation error messages
         messages: {
         name: "Please enter your name.",
         comments: "Please briefly describe the trouble you are having!",
      },
      // Make sure the form is submitted to the destination defined
      // in the "action" attribute of the form when valid
     submitHandler: function(form) {
     form.submit();
     }
  });
 });

`

Joe Romo
  • 5
  • 1
  • Does this answer your question? https://stackoverflow.com/questions/19543354/jquery-validate-set-conditional-rules-based-on-user-selection – mykaf Feb 20 '23 at 20:40

0 Answers0