/    Sign up×
Community /Pin to ProfileBookmark

Display Mulitple Select Box "SELECTED"

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.

[CODE]
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>”);
[/CODE]

to post a comment
HTML

1 Comments(s)

Copy linkTweet thisAlerts:
@ray326Apr 05.2007 — 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.
×

Success!

Help @magoo100 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...