aspose file tools*
The moose likes Servlets and the fly likes populate a drop-down listbox Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "populate a drop-down listbox" Watch "populate a drop-down listbox" New topic
Author

populate a drop-down listbox

nitij kumar
Greenhorn

Joined: Dec 08, 2000
Posts: 2
Is there an easy way using JSP/JavaBeans to populate a drop-down listbox based on a value that is chosen in a previous drop-down listbox?
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
If by "previous" you mean on a previous page, which has been submitted to a servlet/JSP, then it's fairly straightforward. If you mean another listbox on the same page then it's not a simple problem.
You might find the code examples at the following old thread helpful.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
manav kher
Ranch Hand

Joined: Nov 21, 2000
Posts: 98
well i am assuming you mean a listbox in html and from "previous listbox" you mean a listbox in the previous (not current) page...in that case its pretty simple simply either use a jsp variable in html to set the value of the list box for eg
<form name="myform">
<select name="myselect" rows=1>
<option><%=jspVar0%></option>
<option><%=jspVar2%></option>
........
....
</select>
</form>
or use javascript to add or edit items in a list box in the current page for eg
<script>
document.myform.myselect.options[0].text="sometext"(or <%=jspVar%>
</script>

manav
nitij kumar
Greenhorn

Joined: Dec 08, 2000
Posts: 2
I would frame my query in a better way
I am using Javabeans say for example,
<jsp:useBean id="formHandler" class="foo.FormBean" scope="request">
<jsp:setProperty name="formHandler" property="*"/>
</jsp:useBean>
Now i need to set the getter/setter methods,
Here I access a textbox like this
public String getFirstName() {
return firstName;
}
//The Setter method
public void setFirstName(String fname) {
firstName =fname;
}
This particular piece of Info I retain to use in later pages,
Similarly How would i go about ListBoxes which has fixed values and once selected by user is retained/Used in later pages.
Warm Regards to all
Rajesh Hegde
Ranch Hand

Joined: Sep 15, 2000
Posts: 112
You can try this may be.
The listboxes LB1 & LB2 are in lets say demo.jsp. And u want to populate LB2 depending on the value in LB1. In the OnChange event handler for LB1 submit the form to demo.jsp itself by sending the selected value as data to the jsp. Then u can use the getparameter method within demo.jsp to populate the LB2 dynamically.
The whole point is about the jsp calling itself. I did a similar code recently and it worked perfect.
Rajesh
bredan
Greenhorn

Joined: Dec 20, 2000
Posts: 11
In the JavaBean, I would use a string array to store the values of the dropdown listbox. In next page, you can retrieve the string array to populate the dropdown listbox
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
Please note that The Java Ranch has a naming policy, described here and "bredan" is not a valid name. Please choose one which meets the requirements.
Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: populate a drop-down listbox