Getting index from a select object?

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

    Getting index from a select object?

    I have the following selectbox in my jsp page:

    <select name="myNumber" >
    <option value="1">One
    <option value="2">Two
    <option value="3">Three
    </select>

    <%
    String myNumber = request.getPara meter("myNumber ");
    int n = Integer.parseIn t(myNumber);

    %>

    With this javacode I am able to store the index of the option choosen from
    the select object, in n.

    But I think its confusing that converting the name of an option into a int
    gives its corresponding value.

    Normally that would throw a NumberFormatExc eption:

    String z = "Peter";
    int k = Integer.parseIn t(z);

    throws exception.

    How can it be legal to convert String "myNumber" into an int?


  • David Dorward

    #2
    Re: Getting index from a select object?

    JS wrote:
    [color=blue]
    > I have the following selectbox in my jsp page:[/color]

    Java is to JavaScript as Car is to Carpet[1]. Posts about Java Server Pages
    should be addressed to a Java newsgroup.


    [1] Stolen from someone (I think in this newsgroup) who I would credit if I
    could remember who.

    --
    David Dorward <http://blog.dorward.me .uk/> <http://dorward.me.uk/>
    Home is where the ~/.bashrc is

    Comment

    • Thomas 'PointedEars' Lahn

      #3
      Re: Getting index from a select object?

      David Dorward wrote:
      [color=blue]
      > JS wrote:[color=green]
      >> I have the following selectbox in my jsp page:[/color]
      >
      > Java is to JavaScript as Car is to Carpet[1]. [...]
      >
      > [1] Stolen from someone (I think in this newsgroup) who I would credit if
      > [I could remember who.[/color]

      Google is your friend. [psf 6.1]

      <http://groups.google.c om/groups?as_q=jav ascript+java+ca r+carpet&as_ugr oups=comp.lang. javascript&scor ing=d&filter=0>


      HTH & HAND

      PointedEars :)

      Comment

      Working...