/    Sign up×
Community /Pin to ProfileBookmark

Select object value

Hi,

I just saw the following:
[URL=”http://www.w3schools.com/jsref/prop_option_value.asp”]http://www.w3schools.com/jsref/prop_option_value.asp[/URL]

And wonder if there’s something wrong with [I]selectObject.value[/I]. 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>[/CODE]

It seems to be working with no problem.

Thanks in advance!
Mike

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@nap0leonJun 10.2012 — 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.
×

Success!

Help @Rain_Lover spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 11.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @bahaedd,
tipped: article
amount: 1000 SATS,

tipper: @Balmasexy,
tipped: article
amount: 1000 SATS,

tipper: @mbsaad,
tipped: article
amount: 1000 SATS,
)...