Enable and disable checkbox

Disable 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

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
Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com







    Post your comments , suggestion , error , requirements etc here




    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer