HTML | option value Attribute

The value attribute for <option> tag in HTML is used to specify the value of the option element.

Syntax:

<option value = "value">

Attribute Value: It contains single value value which has to be sent to the server.



Example: This example illustrates the value attribute in option tag.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
    <head>
        <title>HTML option value Attribute</title>
    </head>
      
    <body style = "text-align:center">
          
        <h1 style = "color: green;">
            GeeksforGeeks
        </h1>
          
        <h2>
            HTML option value Attribute
        </h2>
          
        Sorting Algorithms:
        <select id="opt">
            <option value="quick">Quick sort</option>
            <option value="merge">Merge sort</option>
            <option value="insertion">Insertion sort</option>
        </select>
          
        <button type="button" onclick="geek()">
            Click me!
        </button>
          
        <p id = "p"></p>
          
        <script>
            function geek() {
                var x = document.getElementById("opt").selectedIndex;
                var y = document.getElementsByTagName("option")[x].value;
                document.getElementById("p").innerHTML = "The selected" 
                + " option has value equals " + y + ".";
            }
        </script>
    </body>
</html>                    

chevron_right


Output:
Before clicking the button:
optionvalue
After clicking the button:
optionvalue

Supported Browsers: The browser supported by value attribute in option tag are listed below:

  • Apple Safari
  • Google Chrome
  • Firefox
  • Opera
  • Internet Explorer


My Personal Notes arrow_drop_up


If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.