HTML DOM Input Range value property



The HTML DOM Input range value property is associated with the input element having type=”range” and the value attribute. It is used to return the value of slider control value attribute or to set it. The value attribute can be the default value or the value set by dragging the slider.

Syntax

Following is the syntax for βˆ’

Setting the value property βˆ’

rangeObject.value = text;

Here, text is used for specifying the value for the range slider control.

Example

Let us look at an example for the input range value property βˆ’

 Live Demo

<!DOCTYPE html>
<html>
<body>
<h1>Input range Value property</h1>
<form>
VOLUME <input type="range" id="RANGE1" name="VOL">
</form>
<p>Get the above element value by clicking the below button</p>
<button onclick="getValue()">Get Value</button>
<p id="Sample"></p>
<script>
   function getValue() {
      var t = document.getElementById("RANGE1").value;
      document.getElementById("Sample").innerHTML = "The value for the radio button is : "+t;
   }
</script>
</body>
</html>

Output

This will produce the following output βˆ’

On clicking the β€œGet Value” button βˆ’

In the above example βˆ’

We have created an input field contained inside a form having type=β€œrange”, id=β€œRANGE1”, name=β€œVOL” βˆ’

<form>
VOLUME <input type="range" id="RANGE1" name="VOL">
<form>

We have then created a button β€œGet Value” that will execute the getValue() method when clicked by the user βˆ’

<button type="button" onclick="getValue()">Get Value</button>

The getValue() method gets the input element using the getElementById() method and assigns its β€œvalue” attribute value to variable t. This variable is then displayed in the paragraph with id β€œSample” using its innerHTML property βˆ’

function getValue() {
   var t = document.getElementById(β€œRANGE1").value;
   document.getElementById("Sample").innerHTML = "The value for the input field is : "+t;
}
Updated on: 2019-08-22T12:46:44+05:30

915 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements