wood burning stoves 2.0*
The moose likes JSP and the fly likes Dynamic Combo Box 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 » Java » JSP
Bookmark "Dynamic Combo Box" Watch "Dynamic Combo Box" New topic
Author

Dynamic Combo Box

Pol Appan
Ranch Hand

Joined: Aug 26, 2004
Posts: 144
Hello,

I have a JSP page where I am passing parameters to this page.
I have a dynamic combo box and in the onChange event of the combox box I am reloading the page using script.

How do I retain the same value in the combo before it's getting refreshed. Eg: If the user picks 2 from the combo, after the page get's refreshed, the selected value should be 2.

How can I do this and besides is there any method of refreshing the page using JSP method.

Any help is highly appreciated.

Thanks

Cosmos


Never take anything for granted because you never know when you will lose it
Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820

1) pass the "2" as a parameter in the GET or POST or SESSION variable
and when building the combobox again, check each option to see if it matches the parameter you saved.

OR
2) pass the "2" as a parameter in the GET or POST or SESSION variable and after the page loads, call a javascript function that takes this parameter as an argument and sets the combobox to the correct value

OR

3)look at why you are refreshing the page. Is it possible to accomplish the same thing with Dynamic HTML or do you have to go back to the server for some reason?
Pol Appan
Ranch Hand

Joined: Aug 26, 2004
Posts: 144
Yes I need to refresh the page in order to load the values again from the database based on the combo box value which user selects.

Cosmos
Vicky Mohan
Ranch Hand

Joined: Oct 14, 2004
Posts: 130
When you submit the form, you should be able to get the value selected using request.getParameter("XXXXXX") . Then can set the value in request OR session and while displaying, can loop through the collection and mark the one that matches as SELECTED.

It should not be difficult, if you can show yout logic for populating the list box, we can provide further details
Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820

regarding my third option:
I was suggesting that you look at dynamic combo boxes in which all the data that might populate the other combo boxes is downloaded when the page first loads and with javascript, combo boxes are repopulated with the right data after our first combobox changes.

here are some instructions:
dynamic select boxes
Pol Appan
Ranch Hand

Joined: Aug 26, 2004
Posts: 144
OK, thanks for the reply, I will try that

Cosmos
[ January 21, 2005: Message edited by: Cosmos Ja ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Dynamic Combo Box
 
Similar Threads
Retaining selected value in combo box after refresh
Struts combo box
calling a bean from java script
retaining the combo box values
combo boxes and iterator