Multiple Select

[nobr]Hi,

I am having problems with the multiple select option of html. Here are two pages which demonstrate:

Showlist.html:

<html>

<head>

<title>List</title>

</head>

<body>

<form action="listout.jsp" method="post">

<select multiple="multiple" size="5" name="optionlist">

<optgroup label="numbers">

<option value="one">one</option>

<option value="two">two</option>

<option value="three">three</option>

<option value="four">four</option>

</optgroup>

</select>

<br/>

<input type="submit"/>

</form>

</body>

</html>

listout.jsp

<%@page import="java.util.*"%>

<HTML>

<BODY>

<%

Enumeration e = request.getParameterNames();

while(e.hasMoreElements())

{

%>

<%=e.nextElement()%><BR/>

<%

}

%>

<%=request.getParameter("optionlist")%><BR/>

</BODY>

</HTML>

Basically I want to be able to use ALL of the options selected in my jsp page. When I select 'one' and 'four' the paramter mainlist = 'one' the first item selected. I cannot see how to read all of the items.

Does anyone know how to do this. I really want to keep within the confines of JSP or HTML, I do not want to include JScript if I can avoid it.[/nobr]

[1864 byte] By [Crispsa] at [2007-11-27 11:15:40]
# 1

change your code like below:

while (e.hasMoreElements()) {

String key = (String)e.nextElement();

String[] values = request.getParameterValues(key);

for(int i = 0; i < values.length; i++) {

out.print(values[i] + " ");

}

}

skp71a at 2007-7-29 14:14:41 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

cheers, Simple when you know how :-)

Crispsa at 2007-7-29 14:14:41 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

10 dukes?!!?

sorry, thanks, you have given it.

Message was edited by:

skp71

skp71a at 2007-7-29 14:14:41 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...