Enable and disable checkbox
JavaScript JS Validation Checkbox
We can disable or enable a checkbox by managing its disabled property. Here is an example on how to make a checkbox enable or disable. We have used getElementByID to know about the checkbox.
document.getElementById('ck1').disabled=true;
To make it enabled we have to use like this
document.getElementById('ck1').disabled=false;
DEMO of Checkbox Disable →
Managing Checkboxes by Reading status and validating with option to enable or disable in a form
VIDEO
Here is the code
<html>
<head>
<title></title>
<META NAME="DESCRIPTION" CONTENT="">
<META NAME="KEYWORDS" CONTENT="">
<script type="text/javascript">
function chk_control(str) {
if(str=='dsb'){document.getElementById('ck1').disabled=true;}
else {document.getElementById('ck1').disabled=false;}
}
</script>
</head>
<body >
<form name=form1 method=post action=check.php>
<table>
<tr><td ><input type=checkbox name=ckb id=ck1 value=1>
</td><td >PHP</td></tr>
<tr><td >
<input type=button value='Disable' onClick="chk_control('dsb')";>
</td><td >
<input type=button value='Enable' onClick="chk_control('enb')";>
</td></tr>
</table></form>
</body>
</html>
Validate Checkbox in a form →
← JavaScript Checkbox Reference
← JavaScript Basic
← Subscribe to our YouTube Channel here
This article is written by plus2net.com team.
plus2net.com