Option valueProperty
Option Object
Definition and Usage
The value property sets or returns the value of an option (the data sent to the server when the form is submitted).
Tip:If this option is selected when the form is submitted, the value will be submitted with the form.
Syntax
Set the value property:
optionObject.value="text"
Return the value property:
optionObject.value
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the value property.
Example
Example
Display the value of the selected option:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Example (example.com)</title>
<script>
function displayResult(){
var x=document.getElementById("mySelect").selectedIndex;
alert(document.getElementsByTagName("option")[x].value);
}
</script>
</head>
<body>
<form>
Choose your favorite fruit:
<select id="mySelect">
<option value="apple">Apple</option>
<option value="orange">Orange</option>
<option value="pineapple">Pineapple</option>
<option value="banana">Banana</option>
</select>
</form>
<button type="button" onclick="displayResult()">The value of the selected fruit.</button>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>Example (example.com)</title>
<script>
function displayResult(){
var x=document.getElementById("mySelect").selectedIndex;
alert(document.getElementsByTagName("option")[x].value);
}
</script>
</head>
<body>
<form>
Choose your favorite fruit:
<select id="mySelect">
<option value="apple">Apple</option>
<option value="orange">Orange</option>
<option value="pineapple">Pineapple</option>
<option value="banana">Banana</option>
</select>
</form>
<button type="button" onclick="displayResult()">The value of the selected fruit.</button>
</body>
</html>
Try it Yourself »
Option Object Other Extensions