470,855 Members | 1,248 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,855 developers. It's quick & easy.

Getting selected values from a select statement

Hi,

I have the following code in the HTML

<select size="1" name="newtitle">
<% // Need to fill select with available campuses
while (titleit.hasNext())
{
temp = (String)titleit.next();
// Check if it is the selected campus already
if (temp.equals(title))
{
// Make it the selected campus by default
out.println("<option selected>"+temp+"</option>");
}
else
{
// Add it normally
out.println("<option>"+temp+"</option>");
}
}

Which just fills up a combo box. Now in the JSP on the submit page I have

String[] titleU = request.getParameterNames("newtitle");

If I use following line I get an error...

out.println(titleU[0]);

Whats the deal??
Tripharn
Jul 17 '05 #1
2 4838
In article <MT*******************@news-server.bigpond.net.au>,
"Tripharn Teki" <te****@bigpond.net.au> wrote:
Hi,

I have the following code in the HTML

<select size="1" name="newtitle">
<% // Need to fill select with available campuses
while (titleit.hasNext())
{
temp = (String)titleit.next();
// Check if it is the selected campus already
if (temp.equals(title))
{
// Make it the selected campus by default
out.println("<option selected>"+temp+"</option>");
}
else
{
// Add it normally
out.println("<option>"+temp+"</option>");
}
}

Which just fills up a combo box. Now in the JSP on the submit page I have

String[] titleU = request.getParameterNames("newtitle");

If I use following line I get an error...

out.println(titleU[0]);


This shouldn't even compile. getParameterNames()
returns an Enumeration, not an array.

If you mean getParameterValues(), did you remember
the </select>? You don't show it above.
Jul 17 '05 #2
Yea ooops, it was getParameterValues()

But the problem was that in the select statements you need to add
value=blah... which I didn't have...
So essentially in the selectbox you can have someting like Hello World, but
the value can be different, or nothing if you completely miss it out.

Thanks anyway,
Tripharn

"Chris Riesbeck" <ri******@cs.northwestern.edu> wrote in message
news:ri****************************@news.it.northw estern.edu...
In article <MT*******************@news-server.bigpond.net.au>,
"Tripharn Teki" <te****@bigpond.net.au> wrote:
Hi,

I have the following code in the HTML

<select size="1" name="newtitle">
<% // Need to fill select with available campuses
while (titleit.hasNext())
{
temp = (String)titleit.next();
// Check if it is the selected campus already
if (temp.equals(title))
{
// Make it the selected campus by default
out.println("<option selected>"+temp+"</option>");
}
else
{
// Add it normally
out.println("<option>"+temp+"</option>");
}
}

Which just fills up a combo box. Now in the JSP on the submit page I have

String[] titleU = request.getParameterNames("newtitle");

If I use following line I get an error...

out.println(titleU[0]);


This shouldn't even compile. getParameterNames()
returns an Enumeration, not an array.

If you mean getParameterValues(), did you remember
the </select>? You don't show it above.

Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

23 posts views Thread by middletree | last post: by
2 posts views Thread by John | last post: by
4 posts views Thread by planetthoughtful | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.