I have an html list with some items loaded. I am able to get the select list object using the following code:
var list = document.getElementById('ddlReason');
but I need help with figuring out how to detect which value has been chosen from the list.
// Gets your select
var list = document.getElementById('ddlReason');
// Get the index of selected item, first item 0, second item 1 etc ...
var INDEX = list.selectedIndex;
// Viola you're done
alert(list[INDEX].value);
Edit (forgot .value).
You can also make that a bit more concise, but I wanted to make it readable so you could see what was going on. Shorter version:
var list = document.getElementById('ddlReason');
alert(list[list.selectedIndex].value);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With