/    Sign up×
Community /Pin to ProfileBookmark

simple noob question

Hey just starting out at js and have a small problem.
I have a drop down menu that I want to write back what the users selection is.
I can get the value of it by using eg: placevalue=document.getElementById(“locstat”).value;
OpenWindow.document.write(“<p>You have asked fro a package to be delivered” + placevalue + “.</p>”);

but I dont want the value, I want the label that they selected.

like if my menu had the following items
<select name=”place” id=”locstat”>
<option value=”3″>Brisbane $3</option>
<option value=”5″>Melbourne $5</option>
<option value=”4″>Sydney $4</option>
<option value=”6″>Adelaide $6</option>
<option value=”8″>Perth $8</option>
<option value=”7″>Hobart $7</option>
<option value=”6″>Darwin $6</option>
</select>
I want to write back eg: brisbane $3 or which ever one they select not its value.

thanks in advance

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@FangJun 22.2008 — document.getElementById("locstat").text
Copy linkTweet thisAlerts:
@pearmanauthorJun 22.2008 — Thanks for the reply fang... But thats not working for me

I'm probably missing something but I put .text in like so

name1=document.getElementById("locstat").text;

OpenWindow.document.write("<p>This will cost you $" + name1 + ".</p>");

and I just get "undefined" in the popup where the name should be.

If I change .text to .value it returns the value no problem. But of course I want the name.

thanks
Copy linkTweet thisAlerts:
@FangJun 22.2008 — document.getElementById('locstat')[document.getElementById('locstat').selectedIndex].text
×

Success!

Help @pearman 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 5.4,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

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