How To Pass The Selected Value To Java Script Function Inside Of Select Tag In Html?
Solution 1:
Not that I agree with how you're doing things here (in side the tag), technically it is possible to do what you ask by the following:
<form><SELECTNAME="sel"onChange="split(this.value)"><OPTIONVALUE=1>Milk</option><OPTIONVALUE=2>tea</option><OPTIONVALUE=3>water</option><OPTIONVALUE=4>coffee</option></SELECT></form>
Solution 2:
You cannot pass the value directly to the handler but you can get the values in it, I'd recommend to do this in code and not use inline event handlers:
varselect = document.forms[0].sel;
select.onchange = function(){
varvalue = select.options[select.selectedIndex].value; // to get Valuevar text = select.options[select.selectedIndex].text; // to get Text
}
Here's a working example:
Solution 3:
<html><head><script>functionsplit(value)
{
alert(value);
}
</script></head><body><form><SELECTNAME="sel"onChange="split(value)"><OPTIONVALUE=1>Milk</option><OPTIONVALUE=2>tea</option><OPTIONVALUE=3>water</option><OPTIONVALUE=4>coffee</option></SELECT></form><body></html>
use "value". hope this was helpful
Solution 4:
this.options[this.selectedIndex].value
*assuming you want to put it inline inside the onchange attribute
Post a Comment for "How To Pass The Selected Value To Java Script Function Inside Of Select Tag In Html?"