Javascript Reference - HTML DOM Input Range disabled Property








The disabled property disables or enables a slider control.

Browser Support

disabled Yes Yes Yes Yes Yes

Syntax

Return the disabled property.

var v = rangeObject.disabled 

Set the disabled property.

rangeObject.disabled=true|false

Property Values

Value Description
true|false Disable or enable a slider control
  • true - The slider control is disabled
  • false - Default. The slider control is not disabled




Return Value

A Boolean type value, true if the slider control is disabled, otherwise false.

Example

The following code shows how to check if a slider control is disabled or not.


<!DOCTYPE html>
<html>
<body>
<input type="range" id="myRange" disabled>
<button onclick="myFunction()">test</button>
<!--   w w w.  j a v  a  2 s .co m-->
<p id="demo"></p>

<script>
function myFunction() {
    var x = document.getElementById("myRange").disabled;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The code above is rendered as follows:





Example 2

The following code shows how to disable and enable a slider control.


<!DOCTYPE html>
<html>
<body>
<!--from   www.ja v  a  2s  .  co m-->
<input type="range" id="myRange"><br><br>

<button onclick="disableBtn()">Disable Slider Control</button>
<button onclick="enableBtn()">Enable Slider Control</button>

<script>
function disableBtn() {
    document.getElementById("myRange").disabled = true;
}
function enableBtn() {
    document.getElementById("myRange").disabled = false;
}
</script>

</body>
</html>

The code above is rendered as follows: