Alert the value of the selected option in a drop-down list:
var x = document.getElementById("mySelect").selectedIndex;
alert(document.getElementsByTagName("option")[x].value);
The value property sets or returns the value of the option (the value to be sent to the server when the form is submitted).
Tip: If the value property is not specified for an option element, then the text content will be sent to the server when the container form is submitted.
Return the value property:
optionObject.value
Set the value property:
optionObject.value=value
Value | Description |
---|---|
value | The value to be sent to the server |
Return Value: | A String, representing the value of the value attribute of the option element |
---|
Change the value of a specific option element:
document.getElementById("myOption").value = "newValue";