Forums Register Login

populate a drop-down listbox

+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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 don't always make ads but when I do they're tiny
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 2774 times.
Similar Threads
Populating DropDown Boxes
Strange Problem
How to populate drop down box
Populate listbox from sql
how to generate dynamic drop down menu pulling data from the Collection Object
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 13:37:43.