Item Label of a Dropdown

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

    Item Label of a Dropdown



    hello ng

    is there a way to get the selected item-label (not value)
    of a dropdown-element using js?

    any idea?

    greets
    sascha


  • Vjekoslav Begovic

    #2
    Re: Item Label of a Dropdown

    One way is shown below:
    <html>
    <head>
    <script type="text/javascript">
    function testit(selobj){
    var selectedOption = selobj[selobj.selected Index];
    var label = selectedOption. firstChild.node Value;
    alert(label)
    }
    </script>
    </head>
    <body>
    <select id="sel1" onchange="testi t(this)">
    <option value="1">One</option>
    <option value="2">Two</option>
    <option value="3">Three </option>
    <option value="4">Four</option>
    <option value="5">Five</option>
    </select>

    </body>
    </html>




    "Crescionin i Sascha" <sascha.crescio nini@coop.ch> wrote in message
    news:bgal7o$kgd $1@rex.ip-plus.net...[color=blue]
    >
    >
    > hello ng
    >
    > is there a way to get the selected item-label (not value)
    > of a dropdown-element using js?
    >
    > any idea?
    >
    > greets
    > sascha
    >
    >[/color]


    Comment

    • Lasse Reichstein Nielsen

      #3
      Re: Item Label of a Dropdown

      "Crescionin i Sascha" <sascha.crescio nini@coop.ch> writes:
      [color=blue]
      > is there a way to get the selected item-label (not value)
      > of a dropdown-element using js?[/color]

      selectRef.optio ns[selectRef.selec tedIndex].text

      An option element has two properties: value and text.

      /L
      --
      Lasse Reichstein Nielsen - lrn@hotpop.com
      Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
      'Faith without judgement merely degrades the spirit divine.'

      Comment

      Working...