This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Struts and the fly likes Populating dropdowns without submitting form Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Populating dropdowns without submitting form" Watch "Populating dropdowns without submitting form" New topic

Populating dropdowns without submitting form

Grishma Dube
Ranch Hand

Joined: Jul 01, 2003
Posts: 275
Hi All -

I have a question. Suppose I have 2 dropdowns, based on the value selected from 1st dropdown, the second dropdown gets populated. Both the dropdowns are getting populated from DB or web service.

Is there anyway i can achieve it without submitting the form and reloading the page in Struts. (NOTE: My browser doesn't support AJAX or I do not want to use AJAX).

[ January 04, 2008: Message edited by: Grishma Dube ]
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
One possible way to do this would be to pre-populate JavaScript arrays for the second dropdown based on all possible values of the first dropdown box. You could then use JavaScript to swap out the values of the second dropdown without using AJAX and without submitting the form.

However, your statement about your browser not supporting AJAX is probably not true. If your browser supports any type of JavaScript, it also supports AJAX.
[ January 04, 2008: Message edited by: Merrill Higginson ]

Consultant, Sima Solutions
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
If you cannot or do not want to use Ajax then the only other way that I know to do this is with JavaScript. An Internet search will surely turn up several examples. A JavaScript solution works fine as long as your total list of values is fairly small. A previous project of mine used JavaScript for smaller lists and page refreshes for larger lists. I think the cutoff for "larger" was around 1000 expected items.

Edit: I see Merrill posted while I was typing my response. I will add this...part that can be confusing about the JavaScript approach for dynamic data is that you will be using Java code or tags in your JSP code to create the JavaScript code. For some reason I always get confused when I have to mix the two together.

- Brent
[ January 04, 2008: Message edited by: Brent Sterling ]
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: Populating dropdowns without submitting form
It's not a secret anymore!