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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:50:00+00:00 2026-05-31T03:50:00+00:00

Hello stackoverflow guru’s! This is my first post after having used the site for

  • 0

Hello stackoverflow guru’s! This is my first post after having used the site for a fair while now. My normal realm of expertise is within PHP and MySQL so when I have free time I will start to contribute in those areas.

Now my question:

I have a form I am building for a booking system.

One of the fields is a select field to ascertain how many adults and children are being booked for. The are two separate dropdown select fields with several options.

The rules of the booking script are that a maximum of 8 people can stay with a minimum of 1 adult.

Obviously I could put a condition in the processing PHP file, but thats not very good for the user experience so we want to have it that when a number of people is selected from either dropdown, it fades out any value in the other that would take the total over 8.

The HTML would be like this:

<select id="adults">
  <option value="1">1</option>
  <option selected="selected" value="2">2</option>
  <option value="3">3</option>
  <option value="4">4</option>
  <option value="5">5</option>
  <option value="6">6</option>
  <option value="7">7</option>
  <option value="8">8</option>
</select>

<select id="children">
  <option value="0">0</option>
  <option value="1">1</option>
  <option value="2">2</option>
  <option value="3">3</option>
  <option value="4">4</option>
  <option value="5">5</option>
  <option value="6">6</option>
  <option value="7">7</option>
</select>

What I am having significant issues with is the jQuery code I will need to fade out the irrelevant options, as it needs to work both ways ie. if they select 5 children first, then adult values 4-8 are then blanked out, or if they select 3 adults first, children values 6 and 7 would blank out.

I would post what I have tried so far with jQuery, but I now know it is completely the wrong code as I was going in the direction of using jQuery calculate.

Any ideas? (Many many thanks and appreciation in advance, I am sorry that I cant provide any more info).

Kevin

  • 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-31T03:50:02+00:00Added an answer on May 31, 2026 at 3:50 am

    Try this:

    var cache = {
        $adults:            $('#adults'),
        $children:          $('#children')
    }
    cache.$adultsOptions    = cache.$adults.find('option');
    cache.$childrenOptions  = cache.$children.find('option');
    
    cache.$adults.add(cache.$children).change(function()
    {
        var $this    = $(this),
            other    = $this.is( cache.$adults ) ? '$children' : '$adults',
            max      = 8 - $this.val();
    
        cache[other + 'Options'].each(function()
        {
            $.prop( this, 'disabled', $.attr(this, 'value') > max );
        });
    });
    
    cache.$adults.change();​
    

    Remember to always cache your selectors!!


    Here’s the fiddle: http://jsfiddle.net/ZmBLw/

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

Sidebar

Related Questions

Hello all at StackOverflow.. Reasonably new to this site, but I have had nothing
Suppose I have this code: String encoding = UTF-16; String text = [Hello StackOverflow];
First off - hello, this is my first Stack Overflow question so I'll try
Hello dear users of the stackoverflow! I really like the search form on this
Hello stackoverflow contributors! I have this script that gets the starting position of my
Hello everyone in stackoverflow land, A while back I did a website for a
Hello again stackoverflow! So i build this script: <?php $xmlurl = 'http://api.ipinfodb.com/v2/ip_query.php?key=apikey&ip=127.0.0.100&timezone=false'; $xml =
Hello StackOverflow Community, I hope you guys can help me with this here: On
I have a sentence for example hello this is hello stackoverflow hello. What I
https://stackoverflow.com/a/64983/468251 - Hello, I have question about this code, how made that working with

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.