Sunday, November 16, 2008

Get selected value using JavaScript from select Tag

Getting selected value from drop-down interface or select HTML Tag using JavaScript.

use this code:

document.getElementById('book')
.options[document.getElementById('book').selectedIndex].innerHTML;


details,
document.getElementById('book').selectedIndex, this will give you selected option index

then using that index we can get selected optoin HTML object such as, document.getElementById('book').options[index]

and finally getting its value just use innerHTML property, in my case selected book name.

No comments: