SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Dec 2009
    Posts
    299
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to get select box option value ?

    Here is my code:

    HTML:

    <select name="optionList" id="optionList" size="5">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    </select>


    Jquery:

    $(document).ready(function(event) {
    $('#optionList').on('mouseenter', 'option', function(e) {

    alert(option.mouseentered.value); // This does not work . What is the correct code ?


    });
    });

  2. #2
    SitePoint Mentor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,256
    Mentioned
    32 Post(s)
    Tagged
    4 Thread(s)
    You want this.value.

    Also, rather than using the mouseenter event, it would be better to bind to the change event of the select tag, then it will work for keyboard users too.


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
  •