SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    ::==:: Bonzo_CS's Avatar
    Join Date
    Dec 2003
    Location
    (Cardiff Wales)
    Posts
    747
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Select List Value onchange

    Hi All,

    I can't seem to get the right value with regards to a user selection. Basically I have a select list where onchange I want to extract the value of the option chosen.

    For example my select list:

    <select name="users" id="users" onchange="user_detail(this.options[this.selectedIndex].value)">
    <option val="" SELECTED>Select Below</option>
    <option val="4" >test test : (john)</option>
    <option val="7" >test test : (testsdsdvvv)</option>
    <option val="9" >sssdss sssdss : (passy)</option>
    <option val="2" >Smith Smith : (Smith)</option>
    </select>
    The value of 'this.options[this.selectedIndex].value' is giving the element value as in 'test test : (john)' rather than the val 4?

    Can anyone point me in the right direction with this?

    Thanks in advance.


  2. #2
    SitePoint Enthusiast
    Join Date
    Nov 2006
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's because you have typo:
    Code:
    <option value="
    But if you change your mind and want to have innerHTML of options(text between option tags) use
    Code:
    onchange="user_detail(this.selectedIndex.text)"

  3. #3
    ::==:: Bonzo_CS's Avatar
    Join Date
    Dec 2003
    Location
    (Cardiff Wales)
    Posts
    747
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Lol Cheers bosko !

    That was a silly oversight on my part!

    The problem is now fixed.


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
  •