jQuery in Action, 3rd edition
The moose likes Servlets and the fly likes Multiple select box problems Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Multiple select box problems" Watch "Multiple select box problems" New topic

Multiple select box problems

Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
I'm having problems with a multiple select box in an edit page.
It is a box with categories, and the user may have selected several of the categories when he first registered.
In the edit page, I have problems showing which he already have selected.
My SQL statements:
ResultSet rs3 = stmt3.executeQuery("SELECT * FROM MyCalendarCategories WHERE userid=" + user);
ResultSet rs2 = stmt2.executeQuery("SELECT * from Category ORDER BY catid");
This is how I try to show the selected categories from the MyCalendarCategories table:
<select name="categories" size="8" multiple>
String disp = "";
int val = 0;
boolean cat_test = false;
int catid = 0;
disp = rs2.getString("category");
val = rs2.getInt("catid");
catid = rs3.getInt("catid");
if(val == catid){
cat_test = true;
<%if(cat_test == true){ %>
<option value="<%=val%>" selected> <%=disp%></option>
<%}else{ %>
<option value="<%=val%>"> <%=disp%></option>
cat_test = false;

Any help appreciated!
Frank Carver

Joined: Jan 07, 1999
Posts: 6920
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp .
We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please log in again with a new name which meets the requirements.

Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
I agree. Here's the link: http://aspose.com/file-tools
subject: Multiple select box problems
jQuery in Action, 3rd edition