views:

96

answers:

2

How can i acces an select element if it has been selected?

var select = document.getElementById("select");
if(select.selected == true)

doesnt work any idea?
A: 

document.getElementById("mySelect").value

or

var selObj = document.getElementById("mySelect"); selObj.options[selObj.selectedIndex].value;

Leigh Shayler
without if selection?
streetparade
I normally would have an item at the start of the list such as [Select Value]. Then you test for selectedIndex > 0
Leigh Shayler
A: 

The DOM tree is something like

Select
|-option
|-option
`-option

it is not the select node which can be selected. As such, you need to get the select, browse the childs, and test if the child is selected until you find one.

rds