Click to See Complete Forum and Search --> : Display Mulitple Select Box "SELECTED"


magoo100
04-04-2007, 06:18 PM
Hi,
I have a jsp page that a user can access to edit a row in a database. One of the items on the form is a Select Box where a user can select more then 1 item from a drop down list of 15 items. The form works fine with regards to capturing the users choices and updating the database. The problem is that if the user goes back to the form to edit another field the multiple select box shows nothing as highlighted and thus wipes out all previous selections. How can I get multiple selections to be highlighted? I can and have done it with single selections but I can't seem to get multiple selections to work. :( Can anyone out there point me in the right direction???
Thanks for any and all suggestions.


out.println("<tr><td class=\"formfieldicons\"><td class=\"formfieldlabel\">Add'l Program:</td><td class=\"formfieldvalue\"><select multiple size='2' name=\"newpgms\">");


for (int i = 0; i < pgmList.size(); i++) {
String pgms = pgmList.get(i).toString();
int start = pgms.indexOf(quote);
int end = pgms.indexOf(quote, start + 1);
if (s_pgms.equals(pgms.substring(start+1, end) + ",")) {
pgms = pgms.substring(0, end+1) + " SELECTED " + pgms.substring(end+1);
}
out.println(pgms);
}
out.println("</select></td></tr>");

ray326
04-04-2007, 11:47 PM
out.println() in a JSP? That's really bad coding. In your first line you're nesting table cells or you've dropped a closing tag. You're iterating a collection; why are you then substringing the member? It looks like you need another table in your database if you're storing multiple values in a single field. Given the current schema you'd be better off adding a member to the pgms class that returns its multiple values as another collection. Then you could do a nested loop to determine the selected state.