Getting selected values from a select statement

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tripharn Teki

    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.hasNex t())
    {
    temp = (String)titleit .next();
    // Check if it is the selected campus already
    if (temp.equals(ti tle))
    {
    // Make it the selected campus by default
    out.println("<o ption selected>"+temp +"</option>");
    }
    else
    {
    // Add it normally
    out.println("<o ption>"+temp+"</option>");
    }
    }

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

    String[] titleU = request.getPara meterNames("new title");

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

    out.println(tit leU[0]);

    Whats the deal??
    Tripharn


  • Chris Riesbeck

    #2
    Re: Getting selected values from a select statement

    In article <MTE0b.47223$bo 1.35180@news-server.bigpond. net.au>,
    "Tripharn Teki" <telwyn@bigpond .net.au> wrote:
    [color=blue]
    >Hi,
    >
    >I have the following code in the HTML
    >
    ><select size="1" name="newtitle" >
    > <% // Need to fill select with available campuses
    > while (titleit.hasNex t())
    > {
    > temp = (String)titleit .next();
    > // Check if it is the selected campus already
    > if (temp.equals(ti tle))
    > {
    > // Make it the selected campus by default
    > out.println("<o ption selected>"+temp +"</option>");
    > }
    > else
    > {
    > // Add it normally
    > out.println("<o ption>"+temp+"</option>");
    > }
    > }
    >
    >Which just fills up a combo box. Now in the JSP on the submit page I have
    >
    >String[] titleU = request.getPara meterNames("new title");
    >
    >If I use following line I get an error...
    >
    >out.println(ti tleU[0]);[/color]

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

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

    Comment

    • Tripharn Teki

      #3
      Re: Getting selected values from a select statement

      Yea ooops, it was getParameterVal ues()

      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.no rthwestern.edu> wrote in message
      news:riesbeck-11672D.13080720 082003@news.it. northwestern.ed u...[color=blue]
      > In article <MTE0b.47223$bo 1.35180@news-server.bigpond. net.au>,
      > "Tripharn Teki" <telwyn@bigpond .net.au> wrote:
      >[color=green]
      > >Hi,
      > >
      > >I have the following code in the HTML
      > >
      > ><select size="1" name="newtitle" >
      > > <% // Need to fill select with available campuses
      > > while (titleit.hasNex t())
      > > {
      > > temp = (String)titleit .next();
      > > // Check if it is the selected campus already
      > > if (temp.equals(ti tle))
      > > {
      > > // Make it the selected campus by default
      > > out.println("<o ption selected>"+temp +"</option>");
      > > }
      > > else
      > > {
      > > // Add it normally
      > > out.println("<o ption>"+temp+"</option>");
      > > }
      > > }
      > >
      > >Which just fills up a combo box. Now in the JSP on the submit page I have
      > >
      > >String[] titleU = request.getPara meterNames("new title");
      > >
      > >If I use following line I get an error...
      > >
      > >out.println(ti tleU[0]);[/color]
      >
      > This shouldn't even compile. getParameterNam es()
      > returns an Enumeration, not an array.
      >
      > If you mean getParameterVal ues(), did you remember
      > the </select>? You don't show it above.[/color]


      Comment

      Working...