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 7895817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:44:05+00:00 2026-06-03T07:44:05+00:00

I have used the jquery validate plugin to check select box unique and required.

  • 0

I have used the jquery validate plugin to check select box unique and required.

However, check unique is not working at all and check required is only work for the first select box ,

how to fix this ? Thank you

jquery

        $("#insertResult").validate({
    rules: {
         'select[]': {
              required: true,
              unique: true
          }
       },
   }); 

html

<form id="insertResult" method="post" action="excelSQL.php" >
       <select id="selectField0" name="select[]" style="float:left">
                       <option selected="" value="">Select one</option>
    <option value="Email">Email</option>
    <option value="1_Name2">1_Name2</option>
    </select>


    <select id="selectField1" name="select[]" style="float:left">
    <option selected="" value="">Select one</option>
    <option value="Email">Email</option>
    <option value="1_Name2">1_Name2</option>
    </select>
</form>

Updated:
I have edited the js file which i have done before and i have tried selectField0 or selectField_0 , still no luck

    checkForm: function() {
        this.prepareForm();
        for ( var i = 0, elements = (this.currentElements = this.elements()); elements[i]; i++ ) {
            if (this.findByName( elements[i].name ).length != undefined && this.findByName( elements[i].name ).length > 1) {
                for (var cnt = 0; cnt < this.findByName( elements[i].name ).length; cnt++) {
                    this.check( this.findByName( elements[i].name )[cnt] );
                }
                } else {
            this.check( elements[i] );
        }
        }
    return this.valid();

},

  • 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-06-03T07:44:07+00:00Added an answer on June 3, 2026 at 7:44 am

    This is a common problem with the jQuery validator. There are two ways around this problem:

    Method1:

    Modify the jQuery Validator plug-in so that it handles both by following these instructions: http://www.codeboss.in/web-funda/2009/05/27/jquery-validation-for-array-of-input-elements/

    Method2:

    Apply the Validator to each select individually:

    HTML:

    <form id="insertResult" method="post" action="excelSQL.php" >
        <select id="selectField0" name="select[]" style="float:left" class="error">
            <option selected="" value="">Select one</option>
            <option value="Email">Email</option>
            <option value="1_Name2">1_Name2</option>
        </select>
    
        <select id="selectField1" name="select[]" style="float:left">
            <option selected="" value="">Select one</option>
            <option value="Email">Email</option>
            <option value="1_Name2">1_Name2</option>
        </select>
        ...
    </form>
    

    JavaScript:

     $("#insertResult").find("select").each(function() {
         $(this).validate({
             rules: {
                 'select[]': {
                     required: true,
                     unique: true
                  }
             }
         });
     }); 
    

    Method #3:

    While jQuery plugins can be quite valuable for the more basic tasks, in some cases, what you’re trying to do may in fact be outside the scope of what the plug-in was designed to do. Whenever I hear solutions like “modify the library code”, it makes me think that perhaps that library is just not for me. This depends on the complexity of the modifications, and the likelihood that my coworkers or successors may have trouble figuring out why things stopped working when they updated the plugin to the latest version.

    Thus, method #3 sidesteps the jQuery validator altogether and only uses jQuery to facilitate the basic validation:

    JavaScript:

        // submit handler for form
        $('#insertResult').submit(function(event) { 
    
            // if either field is not selected, show error and don't submit
            if( itemNotSelected( $('#selectField0'), $('#selectField1') ) == true )  { 
    
                $('.error2').css("display","block");
                event.preventDefault(); 
                return false;
    
            } else if( isEqual($("#selectField0"), $("#selectField1") ) == true ) {
    
                $('.error2').css("display","none");
                $('.error1').css("display","block");alert("afda")
                event.preventDefault(); 
                return false;
    
            } 
        });
    
        // hide error text on focus of element
        $('#selectField0, #selectField1').focus(function() {
            $('.error2, .error1').hide();
    
        });
    
    // helper methods to check if both fields are equal
    function isEqual(elem1, elem2) {
        return (elem1.find("option:selected").html() == 
                elem2.find("option:selected").html());
    }
    
    // helper methods to check if one field (or both) is not selected
    function itemNotSelected(elem1, elem2) {
        return ( elem1.find("option:selected").html() == "Select one" || 
                 elem2.find("option:selected").html() == "Select one" );
    }
    

    HTML:

    <select id="selectField0" name="select[]" style="float:left" class="error">
        <option selected="" value="">Select one</option>
        <option value="Email">Email</option>
        <option value="1_Name2">1_Name2</option>
    </select>
    
    <select id="selectField1" name="select[]" style="float:left">
        <option selected="" value="">Select one</option>
        <option value="Email">Email</option>
        <option value="1_Name2">1_Name2</option>
    </select>
    <span class="error2" style="display:none">These are required fields</span>
    <span class="error1" style="display:none">Fields must be unique</span>
    
    <input type="submit" name="submit" value="submit" />
    

    The above code will submit the form if and only if the following conditions are true:

    • Both select boxes have items selected. This meets the “required” condition.
    • The selections are not the same and meets the “unique” condition.

    • When a user focuses the select box, the errors disappear.

    • If the user tries to submit without the above submit conditions being true, the following errors are shown:

    • If one or more select box is not selected, the “These are required fields” message shows.

    • If both are equal and selected, the “Fields must be unique” message shows.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

jQuery Validation plugin is used to validate all form data: http://docs.jquery.com/Plugins/Validation Have 3 select
I have used http://bassistance.de/jquery-plugins/jquery-plugin-validation/ my form validate : $(#form_person).validate({ rules: { username: { required:
Drag is not working after dropping on the area. I have used Jquery UI
I have used jQuery plugin: Validation To validate some input fields, but I need
jQuery return links are not working. I have Used jQuery and the basic Ajax
I have used JQuery within my asp.net page. JQuery is working fine. I could
I have used Jquery UI DatePicker for the option in my form to select
I am working on some website , i have used jQuery UI , for
I have used the jquery auto complete plugin in my rails application and things
I have not used jquery much yet and not very familiar with it. Trying

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.