Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
120
rated 0 times [  121] [ 1]  / answers: 1 / hits: 22561  / 12 Years ago, sun, april 29, 2012, 12:00:00

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?


More From » javascript

 Answers
22

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;

[#85902] Friday, April 27, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
cruzs

Total Points: 710
Total Questions: 113
Total Answers: 100

Location: Nepal
Member since Sat, Jul 18, 2020
4 Years ago
cruzs questions
Thu, Nov 26, 20, 00:00, 4 Years ago
Wed, Oct 28, 20, 00:00, 4 Years ago
Wed, Aug 19, 20, 00:00, 4 Years ago
Sun, Aug 2, 20, 00:00, 4 Years ago
;