Check and Clear all checkbox
Posted: Wed Aug 23, 2006 11:59 am
I have two JavaScript function
The first function check all checkbox on page and the second function clear all selected checkbox.
Now I call the functions with following buttons:
I want to remove this buttons because I need more space on page, and I want to put a checkbox. When checkbox selected I want to call function "checkall" when not selected call "clearAll"
Something like:
But my example select all checkbox and not clear all when checkbox not checked.
What I need to do to solve this problem ?
I don't have much knowledge with JavaScript.
Thanks!
Code: Select all
function checkAll() {
var boxes = document.getElementsByTagName('input');
for (i = 0; i < boxes.length; i++) {
if (boxes[i].type == 'checkbox')
boxes[i].checked = true;
document.getElementById('check_'+ boxes[i].value).style.background = '#FFFFCC';
}
}
function clearAll() {
var boxes = document.getElementsByTagName('input');
for (i = 0; i < boxes.length; i++) {
if (boxes[i].type == 'checkbox')
boxes[i].checked = false;
document.getElementById('check_'+ boxes[i].value).style.background = '';
}
}Now I call the functions with following buttons:
Code: Select all
<input type="button" name="CheckAll" value="Check all" onClick="checkAll(document.myform.list)">
<input type="button" name="ClearAll" value="Clear all" onClick="clearAll(document.myform.list)">Something like:
Code: Select all
<input type="checkbox" name="checkall" onclick="checkAll(document.myform.list)" />';What I need to do to solve this problem ?
I don't have much knowledge with JavaScript.
Thanks!