X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY ANGULAR BOOTSTRAP XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

Option value Property

Option Object Reference Option Object

Example

Return the value of the selected option in a drop-down list:

var x = document.getElementById("mySelect").selectedIndex;
alert(document.getElementsByTagName("option")[x].value);

Try it yourself »


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.


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The value property is supported in all major browsers.


Syntax

Return the value property:

optionObject.value

Set the value property:

optionObject.value=value

Property Values

Value Description
value The value to be sent to the server

Technical Details

Return Value: A String, representing the value of the value attribute of the option element


More Examples

Example

Change the value of a specific option element:

document.getElementById("myOption").value = "newValue";

Try it yourself »


Related Pages

HTML reference: HTML <option> value attribute


Option Object Reference Option Object

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB HOSTING

UK Reseller Hosting

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE

facebook