Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7006885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:32:07+00:00 2026-05-27T21:32:07+00:00

How do I validate checkboxes using this validation script? I’ve tried many different ways

  • 0

How do I validate checkboxes using this validation script?
I’ve tried many different ways to no avail. This is a validation script was on a contact form that I modified for my purposes but cannot figure out how to validate chekboxes with it. Here is my form and validation code.

    <form id="contactForm" action="send-mail.php" method="post">
    <table width="492">
      <tr>
    <th><label>Title:</label></th>
         <td><input name="title"  id="title" type="text" class="form-poshytip" title="Enter your first name" /></td>
            </tr>
      <tr>
    <th><label>Name:</label></th>
         <td><input name="name"  id="name" type="text" class="form-poshytip" title="Enter your first name" /></td>
            </tr>
                <tr>
                   <th><label>Email:</label></th>
                     <td><input name="email"  id="email" type="text" class="form-poshytip" title="Enter your email" /></td>                                 </tr>                               
                    <tr>
                    <th><label>Company:</label></th>
                    <td><input name="company"  id="company" type="text" class="form-poshytip" title="Enter your company" /></td>
                    </tr>
                     <tr>
                    <th><label>Phone: (with area code)</label></th>
                    <td><input name="phone"  id="phone" type="text" class="form-poshytip" title="Enter your phone" /></td>
                    </tr>
                    <tr>
                    <th><label>Fax:</label></th>
                    <td><input name="fax"  id="fax" type="text" class="form-poshytip" title="Enter your fax" /></td>
                    </tr>
                     <tr>
                    <th><label>Street:</label></th>
                     <td><input name="street"  id="street" type="text" class="form-poshytip" title="Enter your first name" /></td>
                     </tr>
                      <th><label>City:</label></th>
                     <td><input name="city"  id="city" type="text" class="form-poshytip" title="Enter your city" /></td>
                     </tr>
                      <th><label>State:</label></th>
                     <td><input name="state"  id="state" type="text" class="form-poshytip" title="Enter your state " /></td>
                     </tr>
                      <th><label>Zip:</label></th>
                     <td><input name="zip"  id="zip" type="text" class="form-poshytip" title="Enter your first name" /></td>
                     </tr>
                     <tr>
                    <th colspan="2"><label>Message:</label></th>
                    </tr>
                    <tr>
                    <th></th>
                    <td><textarea  name="comments"  id="comments" rows="5" cols="20" class="form-poshytip" title="Enter your comments"></textarea></td>
                    </tr>
                           <tr>
                    <th colspan="2"><label>Please Choose:</label></th>
                    </tr>
                     <tr>
                     <td><p>
                       <label>
                          <input  style="width:10%;" type="checkbox" name="checkbox[]" value="Initial Free Consultation" id="CheckboxGroup1"  class="options"/>
                       Initial Free Consultation</label>
                       <br />
                       <label>
                         <input style="width:10%;"  type="checkbox" name="checkbox[]" value=" Internal or External Audit" id="CheckboxGroup2" class="options"/>
                       Internal or External Audit</label>
                       <br />
                       <label>
                         <input style="width:10%;"  type="checkbox" name="checkbox[]" value="Security / Compliance Consulting" id="CheckboxGroup3" class="options"/>
                       Security / Compliance Consulting</label>
                       <br />
                       <label>
                         <input style="width:10%;" type="checkbox" name="checkbox[]" value="Risk Assessment" id="CheckboxGroup4" class="options"/>
                       Risk Assessment</label>
                       <br />
                       <label>
                         <input style="width:10%;" type="checkbox" name="checkbox[]" value="Compliance Readiness" id="CheckboxGroup5" class="options"/>
                       Compliance Readiness</label>
                       <br />
                     </p></td> 
                    <td><p>
                      <label>
                        <input style="width:10%;" type="checkbox" name="checkbox[]" value=" Risk Mitigation" id="CheckboxGroup6" class="options"/>
                        Risk Mitigation</label>
                      <br />
                      <label>
                        <input style="width:10%;" type="checkbox" name="checkbox[]" value="Technical Staffing" id="CheckboxGroup7" class="options" />
                        Technical Staffing</label>
                      <br />
                      <label>
                        <input style="width:10%;"  type="checkbox" name="checkbox[]" value="Pen Testing" id="CheckboxGroup8" class="options"/>
                        Pen Testing</label>
                      <br />
                      <label>
                        <input style="width:10%;"  type="checkbox" name="checkbox[]" value="Compliance Products" id="CheckboxGroup9" class="options"/>
                        Compliance Products</label>
                      <br />
                      <label>
                        <input style="width:10%;" type="checkbox" name="checkbox[]" value="Other" id="CheckboxGroup10" class="options"/>
                        Other</label>
                      <br />
                      </p></td>
                    </tr>
                    <tr>
                    <td><input style="position:relative; z-index:100;" type="submit" value="Submit" name="submit" id="submit" /></td>
                    </tr>
                     </table>
                     <input type="hidden" value="jfhepperle@gmail.com" name="to" id="to" />
                                <input type="hidden" value="" name="from" id="from" />
                                <input type="hidden" value="" name="subject" id="subject" />
                                <input type="hidden" value="" name="sendMailUrl" id="sendMailUrl" />
                        <p id="error" style="position class="warning">Message</p>
                        </form>
                        <p id="success" class="success">Thanks for your comments.</p>

Jquery

 jQuery(document).ready(function($) {

// hide messages 
$("#error").hide();
$("#success").hide();

// on submit...
$("#contactForm #submit").click(function() {
    $("#error").hide();

    //required:

        var title = $("input#title").val();
    if(title == ""){
        $("#error").fadeIn().text("Title required.");
        $("input#title").focus();
        return false;
    }

    //name
    var name = $("input#name").val();
    if(name == ""){
        $("#error").fadeIn().text("Name required.");
        $("input#name").focus();
        return false;
    }

        //email
    var email = $("input#email").val();
    if(email == ""){
        $("#error").fadeIn().text("Email required.");
        $("input#email").focus();
        return false;
    }


    var company = $("input#company").val();
    if(company == ""){
        $("#error").fadeIn().text("Company required.");
        $("input#company").focus();
        return false;
    }

    // phone
    var phone = $("input#phone").val();
    if(phone == ""){
        $("#error").fadeIn().text("Phone required");
        $("input#phone").focus();
        return false;
    }

        //fax
    var fax = $("input#fax").val();
    if(fax == ""){
        $("#error").fadeIn().text("Fax required.");
        $("input#fax").focus();
        return false;
    }

    var street = $("input#street").val();
    if(street == ""){
        $("#error").fadeIn().text("Street required.");
        $("input#street").focus();
        return false;
    }

    var city = $("input#city").val();
    if(city == ""){
        $("#error").fadeIn().text("City required.");
        $("input#city").focus();
        return false;
    }

    var state = $("input#state").val();
    if(state == ""){
        $("#error").fadeIn().text("State required.");
        $("input#state").focus();
        return false;
    }

    var zip = $("input#zip").val();
    if(zip == ""){
        $("#error").fadeIn().text("Zip code required.");
        $("input#zip").focus();
        return false;
    }

    // comments
    var comments = $("#comments").val();

    // send mail php
    var sendMailUrl = $("#sendMailUrl").val();

    //to, from & subject
    var to = $("#to").val();
    var from = $("#from").val();
    var subject = $("#subject").val();

    // data string
    var dataString = 'title='+ title
                    + '&name=' + name                        
                    + '&email=' + email
                    + '&company=' + company 
                    + '&phone=' + phone 
                    + '&fax=' + fax
                    + '&street=' + street 
                    + '&city=' + city 
                    + '&state=' + state
                    + '&zip=' + zip 
                    + '&comments=' + comments
                    + '&to=' + to
                    + '&from=' + from
                    + '&subject=' + subject;                                 
    // ajax
    $.ajax({
        type:"POST",
        url: sendMailUrl,
        data: dataString,
        success: success()
    });
});  


// on success...
 function success(){
    $("#success").fadeIn();
    $("#contactForm").fadeOut();
 }

return false;

});

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T21:32:08+00:00Added an answer on May 27, 2026 at 9:32 pm

    For only one checkbox checked:

    if (!$('input[name="checkbox[]"]').is(':checked')) {
        $("#error").fadeIn().text("You must check at least one option.");
    
        return false;
    }
    

    As jQuery documentation of .is() says:

    Description: Check the current matched set of elements against a selector, element, or jQuery object and return true if at least one of these elements matches the given arguments.
    

    Good luck 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the following javascript for form validation: <script type=text/javascript> function validate_form (
I am using JQuery's validate plugin to validate a form. Validation occurs and the
I have a form that I validate it using the JavaScript. Now when I
Using this jQuery validation plugin. http://www.benjaminkeen.com/software/rsv/jquery/index.php I want to validate a checkbox group with
I have a web form that is using this awesome plugin and I'm trying
I've got this validation script for my form (a survey). It loops through all
I'm using jQuery validate on a form I am building and it is working
I'd like to validate a form using the jquery validate plugin, but I'm unable
I am trying to have a checkboxes validation using Javascript, and i am really
the code in symfony that i am using, $this->setWidgets(array( 'mobile' =>new sfWidgetFormInput(), 'subscribetosms' =>new

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.