ServletRequest and combo box newbie question

Discussion in 'Java' started by Santosh, Sep 8, 2004.

  1. Santosh

    Santosh Guest

    Hi,
    Here is a brief description of what my prblem is:
    I have a Combo box in a jsp page that is populated from the database.
    The following code snippet shows how i am populating the combo box.

    //data from the database is there in an Enumeration object tempEnum
    Integer tempInt;
    int tempctr=0;
    while(tempEnum.hasMoreElements()){
    tempInt=((Integer)tempEnum.nextElement());
    tempctr++;
    %>
    <option value="<%=tempctr%>"><%=tempInt.toString()%></option>
    <%
    }
    %>
    I am using a counter (tempctr) to set the values of the combo box
    option as I will need that for further calculations.

    My Question:
    I, not only need to know the option value that is selected, I also
    need to know the option that is selected.

    say for example if the output of the combo box after being populated
    is:
    <select name="select">
    <option value="1">3</option>
    <option value="2">6</option>
    <option value="3">8</option>
    <option value="4">9</option>
    <option value="5">10</option>
    </select>

    In the above case, if the user selects the 3rd option:
    <option value="3">8</option>
    I want to read the value (3 in this case) and also the option (8). How
    can I do that using ServletRequest object? Right now I am able to read
    the value by calling:
    request.getParameter("select");

    I am newbie to java so please excuse my ignorance.
    -Santosh
     
    Santosh, Sep 8, 2004
    #1
    1. Advertising

  2. On 8 Sep 2004 10:32:47 -0700, Santosh wrote:

    Probably a very bad answer, but it occurred
    to me that since you are *putting* the data
    into the select..

    > <option value="<%=tempctr%>"><%=tempInt.toString()%></option>


    ...you might do (something like) this..

    <option
    value="<%=tempctr%>-<%=tempInt.toString()%>">
    <%=tempInt.toString()%>
    </option>

    That way you can get both the counter
    *and* the value displayed in the option.

    HTH

    --
    Andrew Thompson
    http://www.PhySci.org/ Open-source software suite
    http://www.PhySci.org/codes/ Web & IT Help
    http://www.1point1C.org/ Science & Technology
     
    Andrew Thompson, Sep 8, 2004
    #2
    1. Advertising

  3. Santosh

    Chris Smith Guest

    Santosh wrote:
    > <select name="select">
    > <option value="1">3</option>
    > <option value="2">6</option>
    > <option value="3">8</option>
    > <option value="4">9</option>
    > <option value="5">10</option>
    > </select>
    >
    > In the above case, if the user selects the 3rd option:
    > <option value="3">8</option>
    > I want to read the value (3 in this case) and also the option (8). How
    > can I do that using ServletRequest object? Right now I am able to read
    > the value by calling:
    > request.getParameter("select");


    This isn't a Java issue; it's an HTML/HTTP issue, and no choice of
    programming language would be able to solve your problem. The text
    displayed in a drop-down box form element is not sent by the browser to
    the server; so you will need to include all the information in the value
    parameter. There is simply no other way to do it.

    --
    www.designacourse.com
    The Easiest Way to Train Anyone... Anywhere.

    Chris Smith - Lead Software Developer/Technical Trainer
    MindIQ Corporation
     
    Chris Smith, Sep 8, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Joerg Gippert

    ServletRequest.setAttribute question

    Joerg Gippert, Jul 30, 2003, in forum: Java
    Replies:
    2
    Views:
    3,157
    Joerg Gippert
    Jul 31, 2003
  2. Replies:
    1
    Views:
    6,224
    Raymond DeCampo
    Jan 24, 2006
  3. sasuke
    Replies:
    3
    Views:
    1,353
  4. dthmtlgod

    Fill Combo Box based on another Combo Box

    dthmtlgod, Nov 16, 2005, in forum: ASP General
    Replies:
    1
    Views:
    622
    Bob Barrows [MVP]
    Nov 16, 2005
  5. SM
    Replies:
    2
    Views:
    401
Loading...

Share This Page