Latest web development tutorials

HTML DOM Option value property

Option Object Reference Option Object

Definition and Usage

value property sets or returns the value of the option (when form submission data will be sent to the server).

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

grammar

Set the value property:

optionObject.value="text"

Returns the value property:

optionObject.value


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support attribute value


Examples

Examples

Display option values ​​have chosen:

<! DOCTYPE html>
<Html>
<Head>
<Meta charset = "utf-8">
<Title> This tutorial (w3big.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 ()"> select value fruit. </ Button>

</ Body>
</ Html>

try it"


Option Object Reference Option Object