Open In App

HTML DOM Input Range defaultValue Property

Improve
Improve
Like Article
Like
Save
Share
Report

The Input Range defaultValue Property in HTML DOM is used to set or return the default value of the slider control. This property is used to reflect the HTML value attribute. 

The main difference between the default value and value is that the default value indicates the default value and the value contains the current value after making some changes. This property is useful to find out whether the range field has been changed or not.

Syntax:

It returns the Input Range defaultValue property.

rangeObject.defaultValue

It is used to set the Input range defaultValue property.

rangeObject.defaultValue = value

Property Values: It contains a single property, i.e, the value that defines the default value for the range field.

Return Value: It returns a string value that represents the default value of the range field.

Example: This example illustrates how to return the Input Range defaultValue property.

HTML




<!DOCTYPE html>
<html>
 
<style>
    #Geek_p {
        font-size: 30px;
        color: green;
    }
</style>
 
<body style="text-align:center;">
 
    <h1 style="color:green;">
        GeeksForGeeks
    </h1>
 
    <h2>DOM Input Range defaultValue property
    </h2>
    <input name="Geek_range" type="range"
           id="Geek_Range" value="50">
    <br>
    <br>
    <button onclick="returnDefault()">
        Click Here to return the defaultValue Property
    </button>
    <p id="Geek_p"></p>
 
 
    <script>
 
        // Set the default value to 10
        document.getElementById(
            "Geek_Range").defaultValue = "10";
 
        // Return the Input Range defaultValue Property
        function returnDefault() {
            var x = document.getElementById(
                "Geek_Range"
            ).defaultValue;
 
            document.getElementById(
                "Geek_p").innerHTML = x;
        }
    </script>
</body>
 
</html>


Output:

Example 2: Below HTML code illustrates how to set the Input Range defaultValue Property.

HTML




<!DOCTYPE html>
<html>
 
<style>
    #Geek_p {
        font-size: 30px;
        color: green;
    }
</style>
 
<body style="text-align:center;">
 
    <h1 style="color:green;">
        GeeksForGeeks
    </h1>
 
    <h2>DOM Input Range defaultValue property
    </h2>
    <input name="Geek_range" type="range"
           id="Geek_Range" value="50">
    <br>
    <br>
    <button onclick="returnDefault()">
        Click Here to Change the defaultValue Property
    </button>
    <p id="Geek_p"></p>
 
 
    <script>
        function returnDefault() {
            var x =
                document.getElementById(
                    "Geek_Range").defaultValue = "10";
 
            document.getElementById(
                "Geek_p").innerHTML = x;
        }
    </script>
</body>
 
</html>


Output:

Supported Browsers:

  • Google Chrome 4 and above
  • Edge 12 and above
  • Firefox 23 and above
  • Opera 11 and above
  • Safari 3.1 and above


Last Updated : 23 Sep, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads