Check or Uncheck all in a group of checkbox in JavaScript
Thursday, March 11, 2010 3:23Posted in category ASP/.NET, PHP Interview Questions
JavaScript code to be kept before head tag.
<SCRIPT LANGUAGE="JavaScript">
function CheckAll(chk)
{
for (i = 0; i < chk.length; i++)
chk[i].checked = true ;
}
function UnCheckAll(chk)
{
for (i = 0; i < chk.length; i++)
chk[i].checked = false ;
}
</script>
HTML Code:
<form name="myform" action="checkboxes.asp" method="post"> <b>Scripts for Web design and programming</b><br> <input type="checkbox" name="check_list" value="1">ASP<br> <input type="checkbox" name="check_list" value="2">PHP<br> <input type="checkbox" name="check_list" value="3">JavaScript<br> <input type="checkbox" name="check_list" value="4">HTML<br> <input type="checkbox" name="check_list" value="5">MySQL<br> <input type="button" name="Check_All" value="Check All" onClick="CheckAll(document.myform.check_list)"> <input type="button" name="Un_CheckAll" value="Uncheck All" onClick="UnCheckAll(document.myform.check_list)">
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.



freeipad says:
June 17th, 2010 at 11:48 am
excellant article, you deserve a free iPad: http://bit.ly/freeipad6