Option value attribute

Definition and Usage

value Property to set or return the value of the option (the value to be sent to the server when the form is submitted).

Tip:If no value is specified for the option element value attributeThen the text content will be sent to the server when the container form is submitted.

See also:

HTML Reference Manual:HTML <option> value Attribute

HTML Reference Manual:HTML <option> Tag

Example

Example 1

Prompt the value of the selected option in the dropdown list:

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

Try it yourself

Example 2

Change the value of a specific option element:

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

Try it yourself

Syntax

Return the value property:

optionObject.value

Set value attribute:

optionObject.value = value

Attribute Value

Value Description
value The value to be sent to the server.

Technical Details

Return Value: A string value representing the value of the option element's value attribute.

Browser Support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support Support Support Support Support