f



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


0
Tripharn
8/20/2003 6:51:24 AM
comp.lang.java 3285 articles. 1 followers. Post Follow

2 Replies
500 Views

Similar Articles

[PageSpeed] 23

In article <MTE0b.47223$bo1.35180@news-server.bigpond.net.au>,
 "Tripharn Teki" <telwyn@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.
0
Chris
8/20/2003 6:08:07 PM
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" <riesbeck@cs.northwestern.edu> wrote in message
news:riesbeck-11672D.13080720082003@news.it.northwestern.edu...
> In article <MTE0b.47223$bo1.35180@news-server.bigpond.net.au>,
>  "Tripharn Teki" <telwyn@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.


0
Tripharn
8/21/2003 7:48:14 AM
Reply: