File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "dependent combo" Watch "dependent combo" New topic

dependent combo

alex pandiyan

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.

    Eric Pascarello

    Joined: Nov 08, 2001
    Posts: 15385
    Double Combo Script:
    I agree. Here's the link:
    subject: dependent combo
    It's not a secret anymore!