...

View Full Version : selectedindex doesn't seem to work



uxair
01-10-2007, 06:05 AM
I'm trying to find the selectedindex of the option which is selected by the user, but the following code show undefined whenever change occurs


<html>
<body>

<form>
<select id="ddlCar" name="cars" onchange="alert( String( document.getElementById( 'ddlCar' ).selectedindex ) );">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat" selected="selected">Fiat</option>
<option value="audi">Audi</option>
</select>
</form>

</body>
</html>

david_kw
01-10-2007, 06:38 AM
You just have to capitalize the 'i' to

.selectedIndex

Subtile but important.

david_kw

Kor
01-10-2007, 11:18 AM
You may use the this self reference to simplify the code

onchange="alert((this.selectedIndex).toString())"

uxair
01-10-2007, 02:21 PM
Thanks



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum