Option value Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Option


The value property sets or gets the value of the option which will be sent to the server when the form is submitted.

Set the value property with the following Values

Value Description
value The value to be sent to the server

Return Value

A String, representing the value of the value attribute of the option element

The following code shows how to Alert the value of the selected option in a drop-down list:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>

Select your favorite fruit:
  <option id="myOption" value="a">Apple</option>
  <option value="orange">Orange</option>
</select>//w  w  w  .j  a  v  a 2  s .  co m

<button type="button" onclick="myFunction()">Test</button>

<p id="demo"></p>

function myFunction() {
    var v = document.getElementById("myOption").value;
    document.getElementById("demo").innerHTML = v;


Related Tutorials