The value
property sets or gets the value attribute of a slider control.
value |
Yes | 10.0 | Yes | Yes | Yes |
Return the value property.
var v = rangeObject.value
Set the value property.
rangeObject.value=number
Value | Description |
---|---|
number | Set the value of the slider control. The default value is '50' |
A String type value representing a number that represents the default value of the slider control.
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:
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: