/    Sign up×
Community /Pin to ProfileBookmark

HTML setElementById()????

Hi,

I am stuck with a problem ….

A user is face with two selections A and B,

[code]
<SELECT ID=”OPTION_A” onChange=”validate()”>
<OPTION SELECTED=”TRUE” VALUE=”-1″>– Please Select Car –</OPTION>
<OPTION VALUE=”Ferrari”>Ferrari</VALUE>
<OPTION VALUE=”Mclaren”>Mclaren</OPTION>
</SELECT>

<SELECT ID=”OPTION_B” onChange=”validate()”>
<OPTION SELECTED=”TRUE” VALUE=”-1″>– Please Select Position–</OPTION>
<OPTION VALUE=”1″>1</VALUE>
<OPTION VALUE=”2″>2</OPTION>
</SELECT>
[/code]

So before the user can submit the selection i have a check, because if the user has selected “Ferrari”, then he can not select anything from B.

[code]
a = document.getElementById(‘OPTION_A’).value;
b = document.getElementById(‘OPTION_B’).value;
if (a= “Ferrari” && b != “-1”)
{
var result = confirm(“Ferrari cannot choose from option B. Deselect it?”,”Yes”,”No”);
if (result = true)
{
*********************************************
HERE IS MY PROBLEM
I want to be able to then set the value of ELEMENT B to -1
I wish there was a simple function like get but set (setElementById) something on the lines of: setElementById(OPTION_B).value = “-1”
But as far as I am aware there is none…is there a way on setting the option value of the select menu!????
**********************************************

}
else
{
….
}
[/code]

If anyone can give me any ideas…it will be highly appreciate it!…also, I am just a beginner…so please go easy on me ?

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@WebnerdOct 08.2007 — document.getElementById('OPTION_B').selectedIndex=-1

or

document.getElementById('OPTION_B').options[0].selected=true;
Copy linkTweet thisAlerts:
@mocasuauthorOct 10.2007 — Thanks a lot!

I used the "options" one and it worked beautifully
×

Success!

Help @mocasu 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.2,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

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