Skip to content
Related Articles

Related Articles

HTML | option value Attribute

View Discussion
Improve Article
Save Article
  • Last Updated : 26 Jul, 2022

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


<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. 


<!DOCTYPE html>
        <title>HTML option value Attribute</title>
    <body style = "text-align:center">
        <h1 style = "color: green;">
            HTML option value Attribute
        Sorting Algorithms:
        <select id="opt">
            <option value="quick">Quick sort</option>
            <option value="merge">Merge sort</option>
            <option value="insertion">Insertion sort</option>
        <button type="button" onclick="geek()">
            Click me!
        <p id = "p"></p>
            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 + ".";

Output: Before clicking the button:


After clicking the button:


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

  • Apple Safari
  • Google Chrome 1
  • Edge 12
  • Firefox 1
  • Opera
  • Internet Explorer

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!