Forum Moderators: open

Message Too Old, No Replies

How can I read the value of an attribute within an option list?

         

digitalv

7:10 pm on Aug 19, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here's the basic list:

<select name="thelist">
<option id="test1" value="1">blah blah1</option>
<option id="test2" value="34">blah blah2</option>
<option id="test3" value="68">blah blah2</option>
</select>

I want to use an onChange in the <select> section that alerts the value of "ID" - not the actual "value" of the option as defined in value=.

How can I see the text in id=?

Trace

7:27 pm on Aug 19, 2008 (gmt 0)

10+ Year Member



Same way as you would alert the value, just change it for id

<select name="thelist" onchange="doSomething(this);">
<option id="test1" value="1">blah blah1</option>
<option id="test2" value="34">blah blah2</option>
<option id="test3" value="68">blah blah2</option>
</select>

<script type="text/javascript">
function doSomething(listObj){
alert(listObj[listObj.selectedIndex].id)
}
</script>