Latest web development tutorials
 

Option value Property

< Option Object

Example

Alert 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