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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:55:31+00:00 2026-05-26T00:55:31+00:00

I need to show/hide options on one select drop down dependant on another select

  • 0

I need to show/hide options on one select drop down dependant on another select drop down options.

The code below shows what I am trying to achieve.

If the ‘column_select’ select menu option is set to ‘1 column’ then the ‘layout_select’ select menu must display only the ‘none’ option.

If the ‘column_select’ select menu option is set to ‘2 column’ then the ‘layout_select’ select menu must display only the ‘layout 1’ and ‘layout 2’ options.

If the ‘column_select’ select menu option is set to ‘3 column’ then the ‘layout_select’ select menu must display only the ‘layout 3’, ‘layout 4’ and ‘layout 5’ options.

<select name="column_select" id="column_select">
    <option value="col1">1 column</option>
    <option value="col2">2 column</option>
    <option value="col3">3 column</option>
</select>

<select name="layout_select" id="layout_select">
    <!--Below shows when '1 column' is selected is hidden otherwise-->
    <option value="col1">none</option>

    <!--Below shows when '2 column' is selected is hidden otherwise-->
    <option value="col2_ms">layout 1</option> 
    <option value="col2_sm">layout 2</option>

    <!--Below shows when '3 column' is selected is hidden otherwise-->
    <option value="col3_mss">layout 3</option>
    <option value="col3_ssm">layout 4</option>
    <option value="col3_sms">layout 5</option>
</select>

So far everything I have tried has failed abysmally…. I am new to jQuery. If anybody could please help it would be much appreciated. Thanks!

  • 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-26T00:55:32+00:00Added an answer on May 26, 2026 at 12:55 am

    Try –

    $("#column_select").change(function () {
        $("#layout_select").children('option').hide();
        $("#layout_select").children("option[value^=" + $(this).val() + "]").show()
    })  
    

    If you were going to use this solution you’d need to hide all of the elements apart from the one with the ‘none’ value in your document.ready function –

    $(document).ready(function() {
        $("#layout_select").children('option:gt(0)').hide();
        $("#column_select").change(function() {
            $("#layout_select").children('option').hide();
            $("#layout_select").children("option[value^=" + $(this).val() + "]").show()
        })
    })
    

    Demo – http://jsfiddle.net/Mxkfr/2

    EDIT

    I might have got a bit carried away with this, but here’s a further example that uses a cache of the original select list options to ensure that the ‘layout_select’ list is completely reset/cleared (including the ‘none’ option) after the ‘column_select’ list is changed –

    $(document).ready(function() {
        var optarray = $("#layout_select").children('option').map(function() {
            return {
                "value": this.value,
                "option": "<option value='" + this.value + "'>" + this.text + "</option>"
            }
        })
    
        $("#column_select").change(function() {
            $("#layout_select").children('option').remove();
            var addoptarr = [];
            for (i = 0; i < optarray.length; i++) {
                if (optarray[i].value.indexOf($(this).val()) > -1) {
                    addoptarr.push(optarray[i].option);
                }
            }
            $("#layout_select").html(addoptarr.join(''))
        }).change();
    })
    

    Demo – http://jsfiddle.net/N7Xpb/1/

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

Sidebar

Related Questions

I need to show/hide some divs depending on selected options. I'm using .change function.
I have a drop-down and need to show hidden div that corresponds to the
I need to show the number of results for a given category, and hide
I have a form select replacement that uses jQuery to show options in a
I'm new to jQuery and need some help to show and hide a div
Hey, can you help me figure this out? I need to hide/show a div
I have a question actually I need one if / else for hide or
I have the following code. What I'm trying to do is to show a
I need to be able to hide 2 options that are displayed from my
I have 3 dropdowns. Depending on the first i need to show different options

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.