Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

Select object value



3:33 am on Jun 9, 2012 (gmt 0)

5+ Year Member Top Contributors Of The Month


I just saw the following:
[w3schools.com ]

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

<!DOCTYPE html>
<script type="text/javascript">
function displayResult()

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>

<button type="button" onclick="displayResult()">Display value of selected fruit</button>


It seems to be working with no problem.

Thanks in advance!


6:32 am on Jun 9, 2012 (gmt 0)

Not only is your way more efficient, their way is flawed. Using their way, they assume that those are the only option elements that will be displayed on your page. Create another select form above theirs, and you'll see what I mean.

is different than
. It depends on what you want to achieve with your code.

If you are using w3schools to learn JavaScript, you should stop, and use a better resource, such as MDN [developer.mozilla.org], or grab a decent book like: JavaScript, The Definitive Guide.

(I also recommend to look into unobtrusive JavaScript [en.wikipedia.org])


5:49 pm on Jun 9, 2012 (gmt 0)

5+ Year Member Top Contributors Of The Month


Thanks for the confirmation and references!

Featured Threads

Hot Threads This Week

Hot Threads This Month