Option value Property
Option Object
Definition and Usage
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.
Syntax
Set the value property:
optionObject.value="text"
Return the value property:
Browser Support

The value property is supported in all major browsers.
Example
Example
Display the value of the selected option:
<html>
<head>
<script>
function displayResult()
{
var x=document.getElementById("mySelect").selectedIndex;
alert(document.getElementsByTagName("option")[x].value);
}
</script>
</head>
<body>
<form>
Select 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()">Display value</button>
</body>
</html>
Try it yourself »
Option Object
Thank You For Helping Us!
Your message has been sent to W3Schools.
Close [X]