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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:19:05+00:00 2026-05-26T12:19:05+00:00

I have a form with set of dropdown fields, each of which has a

  • 0

I have a form with set of dropdown fields, each of which has a default value of “0” and available values of 1-3. These are serving as a priority selection, where the user picks their top 3 items. Each select field name is unique and populated in a PHP foreach loop — I’m just calling it “N” in the example below.

<select class="variable_priority unique required" name="select-N">
    <option value="0"></option>
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
</select>

The “0” value is used as the default/preset value for non-prioritized selections. Using the techniques described here, I have successfully modified JQuery Validate to ensure that the user cannot pick 1, 2 or 3 in more than one dropdown by comparing the class “variable_priority”:

$('.variable_priority').each(function () {
            if ($(this).val() === value && $(this).val() > 0) {
                timeRepeated++;
            }
        });

However, I still need to validate that the user has indeed entered a value of 1, 2 and 3 in any of the select fields, and has not skipped any. Can anyone give me some guidance on how to do this within the context of JQuery Validate?

  • 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-26T12:19:05+00:00Added an answer on May 26, 2026 at 12:19 pm

    After re-working the requirement on JS Fiddle. http://jsfiddle.net/halfcube/aLvc6/

    I think this maybe more closer to your requirement

    HTML

    <div class="selects">
        <select class="variable_priority unique required" name="select[]" required>
            <option value="0">Select</option>
            <option value="1">1</option>
            <option value="2">2</option>
            <option value="3">3</option>
        </select>
        <select class="variable_priority unique required" name="select[]" required>
            <option value="0">Select</option>
            <option value="1">1</option>
            <option value="2">2</option>
            <option value="3">3</option>
        </select>
        <select class="variable_priority unique required" name="select[]" required>
            <option value="0">Select</option>
            <option value="1">1</option>
            <option value="2">2</option>
            <option value="3">3</option>
        </select>
        <select class="variable_priority unique required" name="select[]" required>
            <option value="0">Select</option>
            <option value="1">1</option>
            <option value="2">2</option>
            <option value="3">3</option>
        </select>
    </div>
    <div class="value">
        0
    </div>
    

    CSS

    .valid{
        box-shadow:0 0 10px green;
        -webkit-box-shadow:0 0 10px green;
        -moz-box-shadow:0 0 10px green;
    }
    

    JavaScript

    $(document).ready(function() {
    
        function checkSelected(val) {
            var ret = false;
            $(".variable_priority").each(function() {
                if ($(this).val() === val) {
                    ret = true;
                }
            });
            return ret;
        }
    
        function totalValue() {
            var total = 0;
            $(".variable_priority:first option[value!=0]").each(function() {
                total = total + parseInt($(this).val(), 10);
            });
            return total;
        }
        function totalSelectedValue(){
            var total = 0;
            $(".variable_priority option:selected").each(function() {
                total = total + parseInt($(this).val(), 10);
            });
            return total;
        }
        $('.value').html(totalValue());
        $('.variable_priority').change(function() {
       //     variable_priority = variable_priority + parseInt($(this).val(), 10);
            $('.value').html(totalSelectedValue() + " out of " + totalValue());
    
            $('option', this).each(function() {
                if (checkSelected($(this).val()) && $(this).val() !== "0") {
                    $('.variable_priority option[value=' + $(this).val() + ']').attr('disabled', true);
                } else {
                    $('.variable_priority option[value=' + $(this).val() + ']').removeAttr('disabled');
                }
            });
            if (totalSelectedValue() === totalValue()) {
                $('.selects').removeClass('invalid').addClass('valid');
            } else {
                $('.selects').removeClass('valid').addClass('invalid');
            }
        });
    });
    

    Now I must get back to work.

    enjoy

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

Sidebar

Related Questions

I have a form with 2 divs that each contains a set of fields.
I have a search form built in ASP.NET that has a dropdown list which
I have to render a set of form elements dynamically (based on value selected
So firefox has a nifty mechanism which will try to autocomplete values in fields
I have a set of input fields that are stacked on top of each
I have a ListView control on my form set up like this in details
Okay, so I have this form that is set to preload a DB record
I have set the form decorators in this way: <?php $this->setElementDecorators(array( 'Label', array(array('labelTd' =>
I have a form on my homepage that is set up to submit via
I have a parent form that is set to be TopMost and then I

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.