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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:42:08+00:00 2026-06-15T16:42:08+00:00

I have a dynamic form where the user can add multiple select boxes: <form

  • 0

I have a dynamic form where the user can add multiple select boxes:

<form id="ticket_form">
  <select class="required" name="quantity[1]"></select>
  <select class="required" name="quantity[2]"></select>
  <select class="required" name="quantity[3]"></select>
</form>

At the moment, I’m making sure that the user has chosen a value for each select boxes:

$("#ticket_form").validate({
  rules: {
    'quantity[]': 'required'
  },
  messages: {
    'quantity[]': 'This field is whack'
  }
});

I only actually need to have one of them to have a selected value. What should I do to let the validation pass when at least one of the select boxes has a value?

UPDATE

This is the code that I ended up with to solve my problem as per Ben Barden’s solution:

$.validator.addMethod("groupSelect", (function(value, element, isRunning) {
  return $(".required[value!=\"\"]").length > 0;
}), "At least one must be selected.");

I also added an additional class rule to the required class, so I don’t have to add any more to the actual validation rules:

$.validator.addClassRules({
  'required': {
    'groupSelect': true
  }
});
  • 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-15T16:42:10+00:00Added an answer on June 15, 2026 at 4:42 pm

    For this, you’re pretty much going to have to create your own validation rule, but the rule you need is pretty simple. All members of that class will validate if there exists any member of that class with a value other than the default. Thus, you use the class selector, then filter further by the value not-equals selector, and check if the result contains anything.

        jQuery.validator.addMethod(
        "groupSelect",
        function (value, element, isRunning)
        {
            return $('.groupSelectClass[value!="defaultSelectValue"]').length > 0;
        },
        "At least one must be selected.");
    

    then just apply the groupSelect rule (the one written there) to the groupSelectClass class (which you make sure is added to all of your selectors on generation) and ensure that whatever you have in place of defaultSelectValue is actually the default value for the selectors. Note that this all needs to be set up before the base validate call, not after.

    Edit:

    Further explanation: the above block of code defines a validation rule by the name of groupSelect (or whatever you put there). As written, the groupSelect rule returns valid if and only if at least one of the nodes with the class “groupSelectClass” has some value other than “defaultSelectValue”. If you make sure that everything with the class “groupSelectClass” is a select box with a default value of “defaultSelectValue”, then this rule will return valid if and only if at least one of those select boxes has been set. If you then apply this rule to the “groupSelect” class using the jQuery.validator.addClassRules function, it will cause all of those select boxes to have that as a validation requirement, and display “At least one must be selected.” on validation failure. http://docs.jquery.com/Plugins/Validation/Validator/addClassRules should give you enough understanding of how to use the addClassRules function. Indeed, I’d recommend you read up on the stuff in that site in general, particularly the validation plugin information, if you’re going to be doing much with it.

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

Sidebar

Related Questions

I have a dynamic form that users can add/delete sets of input fields. I
I have... a dynamic populated select box several input boxes a submit button form
I have a dynamic form where the user provides a name and description: <label>Name</label><br
I have a dynamic form that allow to add many fields dynamically, I Know
I have a dynamic dojo form in which I have a dijit.form.Select whose selected
I have a table with one row..user can add or delete rows(using javascript to
I have a simple, dynamic email form field. After the user submits their email,
I have a ext.form.Combobox object that is dynamically populated by ext.data.JsonStore. The user can
I have a dynamic form that is to be displayed using an iPad. This
I have a dynamic form that adds users to the site, made so you

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.