Meaningless Drivel is fun!*
The moose likes HTML, CSS and JavaScript and the fly likes 2 Select Box`s on one page, second needs to load dynamically Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "2 Select Box`s on one page, second needs to load dynamically" Watch "2 Select Box`s on one page, second needs to load dynamically" New topic
Author

2 Select Box`s on one page, second needs to load dynamically

Derick Potgieter
Ranch Hand

Joined: Feb 19, 2004
Posts: 53
Hi,

I`m struggling with an problem on one of my pages, to do with selects.

I need to display a list of countries around the world in a drop down, then when the user selects the first country
I need to populate the second drop down with the towns under that country.
All this data comes from my DB2 database.

This has to be on one page, as I only need the ID from the second drop down to write back to my database.
Now I don�t have a problem to populate the first select, but how do you handle the second if I needs to be dynamically
Loaded from the database?

Thanks, any help will be appreciated?

Rgds
Derick


SCJP, SCJD, SCWCD, SCBCD (JEE)
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
You are going to need to do a post back on the server with an onchange event on the server. Using jsp?

Eric
Derick Potgieter
Ranch Hand

Joined: Feb 19, 2004
Posts: 53
Yes, sorry this buggles my mind a bit. Do you mabe have some code that could help me??

thanks
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
I am assuming jsp?

http://forum.java.sun.com/thread.jspa?threadID=594047&messageID=3121257

Eric
Derick Potgieter
Ranch Hand

Joined: Feb 19, 2004
Posts: 53
Hi, thanks

I am using JSP`s, with struts.

I cant believe that it takes that much effort jsut to get the second select working.

Is there no other way to go though this process using some of struts`s features??

Thanks
Derick
Eugene Lucash
Ranch Hand

Joined: Feb 19, 2005
Posts: 77
You can write a some simple solution.
Imagine a real code instead of pseudo-pseudo-java-code

In POJO's


In Action



In JSP



I hope this give you some insight

[ February 19, 2005: Message edited by: Eugene Lucash ]

[ February 19, 2005: Message edited by: Eugene Lucash ]

[ February 19, 2005: Message edited by: Eugene Lucash ]

[ February 19, 2005: Message edited by: Eugene Lucash ]

[ February 19, 2005: Message edited by: Eugene Lucash ]
[ February 19, 2005: Message edited by: Eugene Lucash ]
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
There is a JavaScript solution if you want to avoid the post back. What you would have to do is write all of the possible items in JavaScript arrays. If you want this, you can search on google for JavaScript Double combo and you should find some results.

Eric
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: 2 Select Box`s on one page, second needs to load dynamically
 
Similar Threads
interdependent drop down list select mysql jsp
using database values to populate drop down menus
Drop down from DataBase problem
How to avoid an action form to be in session
how to populate dropdown box dynamically