Get menu list label

Discussion in 'Javascript' started by Steven, Sep 23, 2006.

  1. Steven

    Steven Guest

    Hi
    I'm sure this is a rather basic question but I can't figure it out
    I have a menu list as follows

    <select name="par" onchange="alert(this.value)">
    <option value="1"><"A"</option>
    <option value="2"><"B"</option>
    <option value="3"><"C"</option>
    </select>

    When I make a selection I can get the id using this.value, how do I get
    the lable ie the A,B orC
     
    Steven, Sep 23, 2006
    #1
    1. Advertising

  2. Steven

    ASM Guest

    Steven a écrit :
    > Hi
    > I'm sure this is a rather basic question but I can't figure it out
    > I have a menu list as follows
    >
    > <select name="par" onchange="alert(this.value)">
    > <option value="1"><"A"</option>
    > <option value="2"><"B"</option>


    <select name="par" onchange="alert(this.value+'\n'+this.text)">
    <option value="1">"A"</option>
    <option value="2">"B"</option>

    > <option value="3"><"C"</option>
    > </select>
    >
    > When I make a selection I can get the id using this.value, how do I get
    > the lable ie the A,B orC
    >


    document.forms['myForm'].par[document.forms['myForm'].par.selectIndex].text;

    brieffly and if in same form

    selectedLabel = par.text;
    selectedValue = par.value;


    --
    ASM
     
    ASM, Sep 23, 2006
    #2
    1. Advertising

  3. Steven

    ASM Guest

    ASM a écrit :
    >
    > document.forms['myForm'].par[document.forms['myForm'].par.selectIndex].text;


    document.forms['myForm'].par[document.forms['myForm'].par.selectedIndex].text;

    ..
     
    ASM, Sep 23, 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. Shapper
    Replies:
    2
    Views:
    748
    Scott Mitchell [MVP]
    May 7, 2005
  2. Josef K.

    <label><div></div></label> allowed?

    Josef K., May 20, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    13,490
    Josef K.
    May 22, 2005
  3. Praveen
    Replies:
    1
    Views:
    996
    Rob Williscroft
    Nov 5, 2006
  4. CSharpner
    Replies:
    0
    Views:
    1,063
    CSharpner
    Apr 9, 2007
  5. Knut Krueger
    Replies:
    8
    Views:
    282
    Knut Krueger
    Aug 20, 2013
Loading...

Share This Page