www.webdeveloper.com
Results 1 to 2 of 2

Thread: Select object value

Hybrid View

  1. #1
    Join Date
    Nov 2009
    Posts
    80

    Select object value

    Hi,

    I just saw the following:
    http://www.w3schools.com/jsref/prop_option_value.asp

    And wonder if there's something wrong with selectObject.value. Why not a simple approach:

    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <script type="text/javascript">
    function displayResult()
    {
    alert(document.getElementById("mySelect").value);
    }
    </script>
    </head>
    <body>
    
    <form>
    Select your favorite fruit:
    <select id="mySelect">
      <option value="apple">Apple</option>
      <option value="orange">Orange</option>
      <option value="pineapple">Pineapple</option>
      <option value="banana">Banana</option>
    </select>
    </form>
    
    <button type="button" onclick="displayResult()">Display value of selected fruit</button>
    
    </body>
    </html>
    It seems to be working with no problem.

    Thanks in advance!
    Mike

  2. #2
    Join Date
    Nov 2007
    Posts
    418
    What you have is exactly what they wrote.

    selectObject = document.getElementById("mySelect")

    You are using document.getElementById to get the object that you want the value of.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles