Select value attribute
Definition and Usage
value
Set or return the value of the selected option in the drop-down list.
See also:
HTML Reference Manual:HTML <select> Tag
Example
Example 1
Change the selected option to "banana":
document.getElementById("mySelect").value = "banana";
Example 2
Return the value of the selected option in the drop-down list:
var x = document.getElementById("mySelect").value;
Syntax
Return the value attribute:
selectObject.value
Set the value attribute:
selectObject.value = value
attribute value
value | description |
---|---|
value |
Specifies the value of the <option> element in the dropdown list that should be selected. If the value does not exist, the dropdown list will display an empty option. |
Technical Details
Return Value: |
String value representing the value attribute of the <option> element in the dropdown list. If the dropdown list allows multiple selections, the first selected option is returned. No content is returned if no option is selected. |
---|
Browser Support
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Support | Support | Support | Support | Support |