Monday 07 July 2008 2:59:45 am
JavaScript check all check box in form
Do you have a problem to check all check box is very more? This script I think it is ok .what do you think.? Hear the JavaScript code Example
<script language="javascript">
function check_all(){ NumChkBox=document.form_check.checkbox.length;
if(document.getElementById('check_all_box').checked==true){
for(i=1;i<=NumChkBox;i++){
NameChekBox="checkbox"+i;
document.getElementById("checkbox"+i).checked=true;
}
}else if(document.getElementById('check_all_box').checked==false){
for(i=1;i<=NumChkBox;i++){
NameChekBox="checkbox"+i;
document.getElementById("checkbox"+i).checked=false;
}
}
} </script> Hear the HTML code Example
<body>
<form id="form1" name="form_check" method="post" action="">
<input type="checkbox" name="checkbox" id="checkbox1" value="checkbox" /> check box1<br>
<input type="checkbox" name="checkbox" id="checkbox2" value="checkbox" /> check box2<br>
<input type="checkbox" name="checkbox" id="checkbox3" value="checkbox" /> check box3<br>
<input type="checkbox" name="checkbox" id="checkbox4" value="checkbox" /> check box4<br>
<input type="checkbox" name="checkbox" id="checkbox5" value="checkbox" /> check box5<br>
<input type="checkbox" name="checkbox" id="checkbox6" value="checkbox" /> check box6<br>
<input type="checkbox" name="checkbox" id="checkbox7" value="checkbox" /> check box7
</form>
<input type="checkbox" name="check_all_box" id="check_all_box" onclick="check_all()" value="checkbox" />
<b>check all box</b> </body>
|