Easy Tutorial
❮ Prop Select Disabled Obj Storage ❯

Option value Attribute


Definition and Usage

The value attribute sets or returns the value of an option (data that will be sent to the server upon form submission).

Tip: When the form is submitted, if this option is selected, the value will be submitted with the form.

Syntax

Set the value attribute:

Return the value attribute:


Browser Support

All major browsers support the value attribute.


Example

Display the value of the selected option:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>tutorialpro.org(tutorialpro.org)</title>
<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()">Show the value of the selected fruit.</button>

</body>
</html>

❮ Prop Select Disabled Obj Storage ❯