/    Sign up×
Community /Pin to ProfileBookmark

Capturing Value of Unselected Drop-Down Box Entry

Is there a way that I can capture the value of the current entry that shows in a Drop-Down Box, when it hasn’t been selected?

Thanks for any help…

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@CrazyMerlinJan 14.2006 — check its 'defaultSelected' property
Copy linkTweet thisAlerts:
@tcurrierauthorJan 14.2006 — Thanks, but I can't seem to get it to work....

[CODE]<form name="myoptions">
<option value="APPL">Apples</option>
<option value="ORAN">Oranges</option> <--- current entry in box
<option value="PEAR">Pears</option>
<option value="PEAC">Peaches</option>
</form>

<script>
alert(document.forms["myoptions"][defaultSelected].value); ??????????
</script>[/CODE]


Thanks...
Copy linkTweet thisAlerts:
@FangJan 14.2006 — Form needs [I]select[/I]:&lt;form name="myoptions"&gt;
&lt;select name="select1"&gt;
&lt;option value="APPL"&gt;Apples&lt;/option&gt;
&lt;option value="ORAN"&gt;Oranges&lt;/option&gt; &lt;--- current entry in box
&lt;option value="PEAR"&gt;Pears&lt;/option&gt;
&lt;option value="PEAC"&gt;Peaches&lt;/option&gt;
&lt;/select&gt;
&lt;/form&gt;
alert(document.forms["myoptions"].select1.options[document.forms["myoptions"].select1.selectedIndex].value);
Copy linkTweet thisAlerts:
@tcurrierauthorJan 14.2006 — Beautiful.... Thank you! Just what I was looking for ....
Copy linkTweet thisAlerts:
@tcurrierauthorJan 16.2006 — Is there a way to set option boxes back to their original value (index 0) using this same type of command ? I have 4 boxes on my page, and I'd like to reset them all to their default values with a click of one button.

[CODE]alert(document.forms["myoptions"].select1.options[document.forms["myoptions"].select1.selectedIndex] =0); [B]????????[/B][/CODE]
Copy linkTweet thisAlerts:
@tcurrierauthorJan 16.2006 — I found it:

[CODE]<script>
function reset_options() {
document.forms["myoptions"].fruit.selectedIndex = 0;
}
</script>[/CODE]
Copy linkTweet thisAlerts:
@FangJan 16.2006 — Resets the form:document.forms["myoptions"].reset();
×

Success!

Help @tcurrier 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 6.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

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