File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes list box problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "list box problem" Watch "list box problem" New topic

list box problem

thejaswi mogenahalli

Joined: Mar 20, 2006
Posts: 1
hi friends
I am new to this forum.
I am problem with my project

in this page i have two list boxes. I have populate the second list box based of the value selected in the first listbox.

<html:select styleClass="input" property="worklevel"
<html ptions name="levelCodes" labelName="levelCodes">
</html ptions>

this is first list box .it is populating itself using a list varible called levelcodes in session.

<html:select styleClass="input" property="dependentlevel">
<html ptions name="dependentlevel" labelName="dependentlevel">
</html ptions>

please help me with this.
i have no idea how to do it.

thanks in advance.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
As I see it, there are 3 ways to handle this. All three of them require the use of javaScript, So if you don't know much about javaScript, I'd suggest you spend some time learning it.

1- Call a function from the onchange event of the first dropdown box to submit the form and cause the action on the server side to read the value of the first dropdown box and populate the values for the 2nd. Then, using the onload event of the <body> tag, you can cause the focus to be placed on the 2nd dropdown box when the page is refreshed. If you use this method you'll need to set some type of flag to indicate whether you're intending to submit the entire form for processing, or only refreshing the 2nd dropdown box.

2- If there are only a few sets of possible options for dropdown box 2, you can create javascript arrays for each of the option sets. Then, use the onchange event of the first dropdown to swap out the options for the 2nd dropdown based on what was selected in the first.

3- Use an AJAX call to the server in the onchange event of the first dropdown box to determine the contents of the 2nd dropdown box.

Consultant, Sima Solutions
I agree. Here's the link:
subject: list box problem
It's not a secret anymore!