permaculture playing cards*
The moose likes HTML, CSS and JavaScript and the fly likes dependent combo Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "dependent combo" Watch "dependent combo" New topic
Author

dependent combo

alex pandiyan
Greenhorn

Joined: Aug 25, 2004
Posts: 10
Hi all,
While my page loads i have 2combo boxes.
If user selects say the 1st combo,based on that the second combo should be populated.How to implement this using javascript?
For ex:1st combo while loading should contain say All sports and 2nd combo should contain all players.
If user selects say tennis in 1st combo,then 2nd combo should be populated with tennis players names alone.

Expecting ur replies in this reg!!!
Julian Kennedy
Ranch Hand

Joined: Aug 02, 2004
Posts: 823
Not continents and countries this time then?

OK, two options for you to consider:
  • you would need a separate list of the tennis players and another one for the football players, e.g. held in a JavaScript array. When the sport selection is changed you would then replace the innerHTML of the players combo with the values from the array.
  • in your players combo you could include the sport in the id field of each option, e.g. tennis players could be T1-T99 and football players could be F1-F99. That way you could filter out tennis players, for example, by removing all ids that don't being with T from the list. You'd need to keep a copy of the originals however.



  • This is what I mean by needing a relationship between the two lists as expressed in this thread you started in the JSP Forum.

    If there is a large number of sports and players this kind of thing is usually done better using the dynamic capabilities of JSP, for example.

    In my opinion, you probably wouldn't want to do it like that in the first place. That's a design issue.

    Jules
    Eric Pascarello
    author
    Rancher

    Joined: Nov 08, 2001
    Posts: 15376
        
        6
    Double Combo Script: http://www.javascriptkit.com/script/cut183.shtml
     
    With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
     
    subject: dependent combo
     
    Similar Threads
    swings and eventhandeling
    jsp dynamic combo box
    How to design a GUI which has n number of component are changing depending on the act
    problem withcombo oxes
    combo boxes and iterator