Javascript DOM HTML Input Checkbox disabled Property set

Introduction

Disable a checkbox:

document.getElementById("myCheck").disabled = true;

Click the button to disable the checkbox.

View in separate window

<!DOCTYPE html>
<html>
<body>

Checkbox: <input type="checkbox" id="myCheck">
<button onclick="myFunction()">Test</button>

<script>
function myFunction() {//from  ww w . ja  va2  s .c  om
  document.getElementById("myCheck").disabled = true;
}
</script>

</body>
</html>

The disabled property sets or gets whether a checkbox should be disabled, or not.

This property mirrors the HTML disabled attribute.

The disabled property accepts and returns a boolean value.

Value Description
true The checkbox is disabled
false Default. The checkbox is not disabled

It returns true if the checkbox is disabled, otherwise it returns false.




PreviousNext

Related