Javascript Reference - HTML DOM Input Range value Property








The value property sets or gets the value attribute of a slider control.

Browser Support

value Yes 10.0 Yes Yes Yes

Syntax

Return the value property.

var v = rangeObject.value

Set the value property.

rangeObject.value=number

Property Values

Value Description
number Set the value of the slider control. The default value is '50'




Return Value

A String type value representing a number that represents the default value of the slider control.

Example

The following code shows how to get the value of a slider control.


<!DOCTYPE html>
<html>
<body>
<!--   w ww .j  a  v a2s.c  om-->
Points: <input type="range" id="myRange" value="20">
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
    var x = document.getElementById("myRange").value;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The code above is rendered as follows:





Example 2

The following code shows how to change the value of a slider control.


<!DOCTYPE html>
<html>
<body>
<input type="range" id="myRange">
<button onclick="myFunction()">test</button>
<!--   w w w. ja  v a2 s  . c om-->
<p id="demo"></p>

<script>
function myFunction() {
    document.getElementById("myRange").value = "75";
}
</script>

</body>
</html>

The code above is rendered as follows: