get attribute value with javascript in select list

javascript

Solution

If you meant get the value from the `car` attribute of the selected option:

//get the option's car attribute at selectedIndex
var car = document.getElementById('test').options[select.selectedIndex].car;

Problem

Possible Duplicate: Use created attribute with javascript in select list im trying to access an attribute that i created in a select list. ``` <script language="JavaScript"> function updateUrl() { var newUrl = document.getElementById('test').getAttribute('car'); alert(newUrl); } </script> <select name= "test" id= "test" onChange= "updateUrl()"> <option value="1" selected="selected" car="red">1</option> <option value="2" car="blue" >2</option> <option value="3" car="white" >3</option> <option value="4" car="black" >4</option> </select> ``` it keep giving me null. how do i get the value from attribute car?

Original source