SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2005
    Posts
    93
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need value associated with selectedIndex

    Hi there,

    I'm trying to get the value associated with a selected index in a drop down list.

    Here's an example:

    HTML Code:
    <select name='elem'>
       <option id='100' value='Hello' name='hello' />
       <option id='200' value='Hello' name='hello' />
    </select>
    My Javascript is as follows - THIS CODE DISPLAYS CONTINUOUS VALUES: 1,2,3...
    Code:
    alert(elem.options.selectedIndex);
    If I were to use the following, I'd get 'undefined' alerts
    Code:
    alert(elem.options.selectedIndex.value);
    The thing is I need the value, not the index.

    Any ideas/references?

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    elem.options[elem.selectedIndex].value

    or just
    elem.value

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2005
    Posts
    93
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    perfect... thanks


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •