Getting selected values from a select statement - Java

This is a discussion on Getting selected values from a select statement - Java ; 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)) { // ...

+ Reply to Thread
Results 1 to 3 of 3

Getting selected values from a select statement

  1. Default 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



  2. Default Re: Getting selected values from a select statement

    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.

  3. Default Re: Getting selected values from a select statement

    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.




+ Reply to Thread

Similar Threads

  1. Select statement for boolean and/or DateTime values?
    By Application Development in forum ADO DAO RDO RDS
    Replies: 2
    Last Post: 10-20-2007, 07:02 AM
  2. Select Statement Help
    By Application Development in forum basic.visual
    Replies: 2
    Last Post: 08-17-2006, 01:07 AM
  3. Replies: 0
    Last Post: 03-14-2005, 01:42 AM
  4. The Select Statement
    By Application Development in forum Clarion
    Replies: 3
    Last Post: 07-01-2004, 07:47 AM
  5. Need help on SQL select statement
    By Application Development in forum basic.visual
    Replies: 1
    Last Post: 12-05-2003, 02:22 PM