hi i have created function that automatically adds rows with chekcboxes. i can create two button that one serves checking all checkboxes and the another one serves for unchecking rows. but i would like to check/uncheck all checkboxes with single checkbox.
then i have created checkbox for the purpose to check or uncheck all checkboxes. but it neigther checks nor unchecks all
here is script
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script>
var a=0;
function add(){
a++;
var cedvel=document.getElementById("tab");
if(a>cedvel.rows.length){
a=cedvel.rows.length;
}
var sira=cedvel.insertRow(a);
var isare=sira.insertCell(0);
var solteref=sira.insertCell(1);
var sagteref=sira.insertCell(2);
var birinci=document.createElement('input');
birinci.type='checkbox';
isare.appendChild(birinci);
solteref.innerHTML=a+1;
var ucuncu=document.createElement('input');
ucuncu.type="text";
ucuncu.size="11";
sagteref.appendChild(ucuncu);
}
function del(){
var cedvel=document.getElementById("tab");
var a=cedvel.rows.length;
for(i=0; i<a; i++){
var komp=cedvel.rows[i].cells[0].childNodes[0];
if(komp.checked==true){
cedvel.deleteRow(i);
a--;
i--;
}
if(i>=0)
cedvel.rows[i].cells[1].childNodes[0].nodeValue=i+1
}
}
function checkall(){
var sec=document.getElementById("tab");
for(i=0; i<sec.rows.length; i++){
sec.rows[i].cells[0].childNodes[0].checked=true;
}
}
function uncheckall(){
var sec=document.getElementById("tab");
for(i=0; i<sec.rows.length; i++){
sec.rows[i].cells[0].childNodes[0].checked=false;
}
}
var checked=1;
function all(){
var sec=document.getElementById("tab");
for(i=0; i<sec.rows.length; i++){
if(checked==1){
sec.rows[i].cells[0].childNodes[0].checked=true;
checked=2;
}
if(checked==2){
sec.rows[i].cells[0].childNodes[0].checked=false;
checked=1;
}
}
}
</script>
</head>
<body bgcolor="#999999">
 <input type="checkbox" onclick="all()" value="check/uncheckall" id="box"/>check/uncheck all
<table id="tab" style="font-family:'Comic Sans MS', cursive">
<tr><td><input type="checkbox" /></td><td>1</td><td><input type="text" size="11" /></td></tr>
</table>
<input type="button" value="add" onclick="add()" style="font-family:'Comic Sans MS', cursive"/><br />
<input type="button" value="delete" onclick="del()" style="font-family:'Comic Sans MS', cursive"/>
<input type="button" value="uncheckall" onclick="uncheckall()" style="font-family:'Comic Sans MS', cursive" /><br />
<input type="button" value="checkall" onclick="checkall()" style="font-family:'Comic Sans MS', cursive" /><br />
</body>
</html>
Thanks in advance for attention