# HTML DOM ...looking for setElementById...



## Mosu (Sep 10, 2003)

Hi,

I am stuck with a problem ....

A user is face with two selections A and B,

-- Please Select Car --
Ferrari</VALUE>
Mclaren

-- Please Select Position--
1</VALUE>
2

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.

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
{
....	
}

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!


----------



## Shadow2531 (Apr 30, 2001)

You mean something like the following?

document.getElementById("OPTION_B").selectedIndex = 0;
or
document.getElementById("OPTION_B").options[0].setAttribute("selected", "selected");
or
document.getElementById("OPTION_B").options[0].selected = true;


----------



## Mosu (Sep 10, 2003)

Thanks a lot! :up:


----------

