/    Sign up×
Community /Pin to ProfileBookmark

Get the select box value just after page loaded

Hi

I am trying to get the (selected/current) value of a select box on an ASP form after the page is being loaded, ie in the startup script.

var RMCat = document.getElementById(“x_RawMat_Category”);
var RMCatValue = RMCat.options[RMCat.selectedIndex].value;

However, I got a blank.

alert(“RMCatValue =” + RMCatValue); gives me ‘RMCatValue =’

Any idea how I can get its value?

Thank you.

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@FangApr 04.2009 — Do the options have a value attribute?
Copy linkTweet thisAlerts:
@rbh033authorApr 04.2009 — Yes, it has.

If I use an onchange event of another field to return the value of this select box, the result is correct.

However, it doesnt work on page loaded.

Below is the source code for the field.
--------------------------------------------------------



<tr>
<td width="200" class="ewTableHeader">Category</td>
<td width="430"><span id="el_RawMat_Category">

<select id="x_RawMat_Category" name="x_RawMat_Category" onchange="ew_UpdateOpt('x_RawMat_Brand','x_RawMat_Category',true);">

<option value="">

Please Select

</option>

<option value="Thermal" selected="selected">

Thermal

</option>

<option value="Thermal" selected="selected">

Thermal

</option>

<option value="Thermal" selected="selected">

Thermal

</option>

<option value="Thermal" selected="selected">

Thermal

</option>

</select>

<input type="hidden" name="s_x_RawMat_Category" id="s_x_RawMat_Category" value="%3C%C2%88J%C2%8EJaI%C2%B5x%C2%8A%C2%9A%0F%C3%8E7)%C3%9D!11!~i%5E%C2%BBz%C3%81%C2%817z%24%23%C2%B53JP8%3F%C2%8D*%C2%8C%C3%B53%C2%A7r%C2%AD%C3%B6q%1B%C3%9Ei!0!%C2%B2%C2%B4N%08!13!%C3%87%C3%88%C3%BAb%C3%86%C3%A5SU%C3%8F%C3%87%C3%8FR%7F%25P%C3%AA%0F%7D%C3%AA%C3%8B%40%C3%87%C2%BF%C3%BE%C3%90%C3%84kS%C2%80%C3%A0%C2%B8!12!%C3%B4)%11%C2%AC'U%C3%BF%1E%C3%A8%C2%8F%C2%A1%C2%87%22%C3%B1%60%C3%9D%C2%97%C3%90%25%C2%96%C3%ACu%C3%9B%3F%1C%C3%BA%19%C3%9E%C2%8A'N%7D%C2%A0%17%C3%8B%C2%AA%C2%BBqX%C3%A0%22%C3%86%C2%B5%C3%982%C3%90%C2%84%C3%90%C2%84%C2%83%23%2C%3A%C3%83_%7D%C3%9F%C2%BC%16%C3%88%C3%85%C3%A9%C3%8C%C3%BCoaM%05v%C2%8E%C2%8EpT%C2%92%C2%95%C3%B4n%C2%99%C3%B7%C2%84l5Yg%7C%C2%90%C3%98%7Dd%C3%A5%C2%BE">

<input type="hidden" name="lft_x_RawMat_Category" id="lft_x_RawMat_Category" value="3">

</span></td>

</tr>
Copy linkTweet thisAlerts:
@FangApr 04.2009 — If all or multiple options are selected, then only the first selected value will be shown, which is "". Your script was returning the correct value.
Copy linkTweet thisAlerts:
@rbh033authorApr 04.2009 — mmm... only one option is allowed for this select box. That is, multiple option is not enabled.
×

Success!

Help @rbh033 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.7,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

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