![]() ![]() |
| RainLover |
Jun 8 2012, 10:17 PM
Post
#1
|
|
Advanced Member ![]() ![]() ![]() ![]() Group: Members Posts: 104 Joined: 16-November 09 Member No.: 10,346 |
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 |
| Christian J |
Jun 9 2012, 12:12 PM
Post
#2
|
|
. ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: WDG Moderators Posts: 4,743 Joined: 10-August 06 Member No.: 7 |
Good question! Thanks for mentioning this, I've always been annoyed by the old verbose syntax.
According to http://quirksmode.org/js/forms.html#sselect "old browsers" don't support it, but it does seem to work in the ones I test with today. It also appears to be mentioned in HTML5: QUOTE select . value [ = value ] Returns the value of the first selected item, if any, or the empty string if there is no selected item. Can be set, to change the selection. |
| RainLover |
Jun 9 2012, 12:42 PM
Post
#3
|
|
Advanced Member ![]() ![]() ![]() ![]() Group: Members Posts: 104 Joined: 16-November 09 Member No.: 10,346 |
I even tried it in IE6 with no problem. You're a star and I'm really grateful to you for your educational answers! |
![]() ![]() |
|
Lo-Fi Version | Time is now: 19th May 2013 - 02:06 PM |