posted 12/27/2009 by Raghav Khunger
In this blog i will show how to disable and enable checkboxes on the click of other checkbox with javascript . I am explaining it by taking a example where there are three checkboxes . On the click of first checkbox the next two checkboxes will get enabled or disabled depending upon the checked state of first checkbox. Here is the sample code:
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script type="text/javascript"> function test() { var chkMain = document.getElementById('chkMain'); var chkFirst = document.getElementById('chkFirst'); var chkSecond = document.getElementById('chkSecond'); if (chkMain.checked) { chkFirst.disabled = 'disabled'; chkSecond.disabled = 'disabled'; } else { chkFirst.disabled = false; chkSecond.disabled = false; } } </script> </head> <body> <div> Toggle the enable status of below checkboxes:<input id="chkMain" type="checkbox" onclick="test();" /><br /> <input id="chkFirst" type="checkbox" /> <input id="chkSecond" type="checkbox" /> </div> </body> </html>
Do let me know your feedback, comments.
What kind of email newsletter would you prefer to receive from CodeAsp.Net?18