<select id="kamal">
<option value"ACTIVE">a<option>
<option value"DISABLED">b<option>
<option value"DELETED">c<option>
</select>
I want to get the value displayed on the page..not the value shown in the option tag
I am interested in "aktiv" not "ACTIVE"
when i write document.getElementById("kamal").value;
then the value that is select comes in the variable. But I want the displayed value.
Please help me how can I take this value.
NOTE: By using all the options given below, it will give me the value of the selected option, I want the label of the selected option. I mean the displayed value on html page.
The solution you are looking for is:
To get the value:
var element = document.getElementById("kamal");
var selectedValue = element.options[element.selectedIndex].value;
To get the text:
var element = document.getElementById("kamal");
var selectedValue = element.options[element.selectedIndex].text;
EDIT:
working example at:
Try:
var sel = document.getElementById("kamal")
alert(sel.options[sel.selectedIndex].value);
Note: your <option>
tags should be closed with </option>
var element = document.getElementById("kamal"); var selectedValue = element.options[element.selectedIndex]. innerHTML;
THis was the solution of my question.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.