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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:13:27+00:00 2026-05-14T06:13:27+00:00

I want to make an HTML form with 2 select boxes. The selected option

  • 0

I want to make an HTML form with 2 select boxes. The selected option in the first select box should drive the options in the second select box. I would like to solve this dynamically on the client (using javascript or jQuery) rather than having to submit data to the server.

For example, let’s say I have the following Menu Categories and Menu Items:

  • Sandwiches
    • Turkey
    • Ham
    • Bacon
  • Sides
    • Mac ‘n Cheese
    • Mashed Potatoes
  • Drinks
    • Coca Cola
    • Sprite
    • Sweetwater 420

I would have two select boxes, named Menu Category and Items, respectively. When the user selects Sandwiches in the Menu Category box, the options in the Items box will only show Sandwich options.

To make this more challenging, let’s assume that I don’t know what the menu items or categories are until I’m ready to send the page to the client. I’ll need some way to “link” the data for the two select lists, but I don’t know how that would be done.

I’m stuck as how I might approach this. Once I filter out the 2nd list one time, how do I “find” the list options once I change my menu category in the 1st list? Also, if I’m thinking in SQL, I would have a key in the 1st box that would be used to link to the data in the 2nd box. However, I can’t see where I have room for a “key” element in the 2nd box.

How could this problem be solved with a combination of jQuery or plain javascript?

  • 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-14T06:13:27+00:00Added an answer on May 14, 2026 at 6:13 am

    Check out this example on Dynamic Drive, or you can search google for “chained select” for other examples.

    Edit: And here is a very nice Remy Sharp tutorial: Auto-populating Select Boxes using jQuery & AJAX


    Well, because I have OCD, I threw together a demo for you.

    It defines a variable could also loaded as json if required.

    HTML

    <select id="cat"></select> <select id="items" disabled></select>
    

    Script

    $(document).ready(function(){
    
    var menulist = { "categories" : [{
     "category" : "Sandwiches",
     "items" : [
       {"name": "Turkey"},
       {"name": "Ham"},
       {"name": "Bacon"}
      ]
     },{
     "category" : "Sides",
     "items" : [
       {"name": "Mac 'n Cheese"},
       {"name": "Mashed Potatoes"}
      ]
     },{
     "category" : "Drinks",
     "items" : [
       {"name": "Coca Cola"},
       {"name": "Sprite"},
       {"name": "Sweetwater 420"}
      ]
     }]
    };
    
    var i,c = '<option>Select a category</option>', opt = $('<option/>');
    var menu = menulist.categories;
    
    for (i=0; i < menu.length; i++){
     c += '<option>' + menu[i].category + '</options>';
    }
    $('#cat')
     .html(c)
     .change(function(){
      var indx = this.selectedIndex - 1;
      if (indx < 0) {
       $('#items').empty().attr('disabled','disabled');
       return;
      }
      var item = '<option>Select an item</option>';
      for (i=0; i < menu[indx].items.length; i++){
        item += '<option>' + menu[indx].items[i].name + '</options>';
      }
      $('#items').html(item).removeAttr('disabled');
     });
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.