question about select in forms

Discussion in 'Javascript' started by Ken1, Dec 16, 2006.

  1. Ken1

    Ken1 Guest

    Hello, lets say i have a select like this:
    <select name="numbers" id="numbers">
    <option value="1">One</option>
    <option value="2">Two</option>
    <option value="3">Three</option>
    </select>

    Lets say a user selects "Two" from the drop down menu... now I want to
    get that "Two" into a variable... but not "2" because i can get 2 by
    using numbers.value..... but how could i get the "Two" into a variable?
     
    Ken1, Dec 16, 2006
    #1
    1. Advertising

  2. Ken1

    ASM Guest

    Ken1 a écrit :
    > Hello, lets say i have a select like this:
    > <select name="numbers" id="numbers">
    > <option value="1">One</option>
    > <option value="2">Two</option>
    > <option value="3">Three</option>
    > </select>
    >
    > Lets say a user selects "Two" from the drop down menu... now I want to
    > get that "Two" into a variable... but not "2" because i can get 2 by
    > using numbers.value..... but how could i get the "Two" into a variable?
    >


    var o = document.forms['myForm'].elements['numbers'].options
    myVariable = o[o.selectedIndex].text;

    o = document.myForm.numbers.options;
    o = document.forms[0].numbers.options;

    <select name="numbers" id="numbers"
    onchange="var k = this.selectedIndex;
    myVariable = this.options[k].text;
    ">

    --
    Stephane Moriaux et son (moins) vieux Mac déjà dépassé
    Stephane Moriaux and his (less) old Mac already out of date
     
    ASM, Dec 16, 2006
    #2
    1. Advertising

  3. Ken1

    Ken1 Guest

    thanks! ill try this out.

    ASM wrote:
    > Ken1 a écrit :
    > > Hello, lets say i have a select like this:
    > > <select name="numbers" id="numbers">
    > > <option value="1">One</option>
    > > <option value="2">Two</option>
    > > <option value="3">Three</option>
    > > </select>
    > >
    > > Lets say a user selects "Two" from the drop down menu... now I want to
    > > get that "Two" into a variable... but not "2" because i can get 2 by
    > > using numbers.value..... but how could i get the "Two" into a variable?
    > >

    >
    > var o = document.forms['myForm'].elements['numbers'].options
    > myVariable = o[o.selectedIndex].text;
    >
    > o = document.myForm.numbers.options;
    > o = document.forms[0].numbers.options;
    >
    > <select name="numbers" id="numbers"
    > onchange="var k = this.selectedIndex;
    > myVariable = this.options[k].text;
    > ">
    >
    > --
    > Stephane Moriaux et son (moins) vieux Mac déjà dépassé
    > Stephane Moriaux and his (less) old Mac already out of date
     
    Ken1, Dec 16, 2006
    #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. Eric
    Replies:
    2
    Views:
    1,529
    Tommy
    Feb 13, 2004
  2. =?Utf-8?B?RGFiYmxlcg==?=

    select gridview row without using select button?

    =?Utf-8?B?RGFiYmxlcg==?=, Mar 3, 2006, in forum: ASP .Net
    Replies:
    5
    Views:
    101,570
    dch31969
    Feb 27, 2009
  3. Eric
    Replies:
    2
    Views:
    596
  4. palmiere
    Replies:
    1
    Views:
    431
    Erwin Moller
    Feb 9, 2004
  5. Bonge Boo!
    Replies:
    5
    Views:
    215
    Bonge Boo!
    Apr 25, 2005
Loading...

Share This Page