Page 1 of 1

checkbox *2 columns off* ????

Posted: Fri Oct 17, 2008 12:10 am
by keane7
Hi guys, im new to php, and this is doing my head in.Im trying to get a select all button for each column to work properly within a dynamic form.

The problem im facing is that, while the button does work, it only works from column 5 onwards.
That being if i click select all in column 5 header, it ticks all within column 3.

The first two columns are made up of ID's and Names pulled from the database, which don't have any checkboxes. All columns after that allowing a manager to check off meeting attendance.

Heres the code im using, its heavily reliant upon the javascript:

Code: Select all

 
<script type="text/javascript">
 
/*Check/Uncheck columns script © John Davenport Scheuer
 *visit: http://www.dynamicdrive.com/forums
 *username: jscheuer1
 *This notice must remain for legal use  */
 
//set 'check all' label
var allp='Check All'
//set 'none' label
var nonep='None'
 
//Multiple tables, each w/unique id? (use 1 for yes, 0 for no)
var tids=1
 
//Initialize 'check all' cells display? (use 1 for yes, 0 for no)
var initca=1
 
/////////////////Stop Editing////////////
allp=new RegExp(allp);
 
function findRow(box){
var tr=box.parentNode;
while (tr.parentNode&&!/^tr$/i.test(tr.tagName))
tr=tr.parentNode;
return /^tr$/i.test(tr.tagName)? tr : null;
}
 
function findCell(box){
var td=box.parentNode;
while (td.parentNode&&!/^th$|^td$/i.test(td.tagName))
td=td.parentNode;
return /^th$|^td$/i.test(td.tagName)? td : null;
}
 
function findCol(box){
var tr=findRow(box);
for (var i_tem = 0; i_tem < tr.cells.length; i_tem++)
if (tr.cells[i_tem]==findCell(box))
return tids? tr.parentNode.parentNode.id+i_tem : i_tem;
}
var boxes=[]
 
function initcheckAll(){
var c=0, inp=document.getElementsByTagName('input');
for (var i_tem = 0; i_tem < inp.length; i_tem++)
if (inp[i_tem].type.toLowerCase()=='checkbox'&&findCell(inp[i_tem])){
boxes[c++]=[inp[i_tem], findCell(inp[i_tem])];
boxes[c-1][0].col=findCol(boxes[c-1][0])
}
for (i_tem = 0; i_tem < boxes.length; i_tem++)
if (allp.test(boxes[i_tem][1].innerHTML)){
for (var i = 0; i < boxes[i_tem][1].childNodes.length; i++)
if(initca&&boxes[i_tem][1].childNodes[i].tagName&&/^div$/i.test(boxes[i_tem][1].childNodes[i].tagName))
boxes[i_tem][1].childNodes[i].style.display='none';
else if(initca&&boxes[i_tem][1].childNodes[i].tagName)
boxes[i_tem][1].childNodes[i].style.display='inline';
boxes[i_tem][0].onclick=function(){
for (var i_tem = 0; i_tem < boxes.length; i_tem++)
if(this.checked&&boxes[i_tem][0].col==this.col)
boxes[i_tem][0].checked=1;
else if (boxes[i_tem][0].col==this.col)
boxes[i_tem][0].checked=0;
};
}
else
boxes[i_tem][0].onclick=function(){
if(!this.checked){
for (var i_tem = 0; i_tem < boxes.length; i_tem++)
if(boxes[i_tem][0].col==this.col){
boxes[i_tem][0].checked=0;
return;
}
}
else{
var b=[];
for (var i_tem = 0; i_tem < boxes.length; i_tem++)
if(boxes[i_tem][0].col==this.col)
b[b.length]=boxes[i_tem][0];
if (!b[0].checked)
for (i_tem = 1; i_tem < b.length; i_tem++)
if(!b[i_tem].checked)
return;
b[0].checked=1;
}
};
}
onload=initcheckAll;
</script>
 
 
 
SECTION FOR COLUMN HEADERS
 
<td class='normalsmall' align='center' >
                                
<input type='checkbox'><span> Check All</span>
</td>   
 
 
 
INSERTING CHECKBOXES THROUGHOUT EACH COLUMN
<td class='normalsmall' align='center' id='".$Meetingid."'>
    <input type='checkbox'>
    </td>
 
 

Re: select all checkboxes *2 columns off*

Posted: Fri Oct 17, 2008 6:57 am
by keane7
Any ideas?? My brain is fried after spending 6 hours on this... lol

Re: checkbox *2 columns off* ????

Posted: Fri Oct 17, 2008 5:20 pm
by califdon
I really don't want to seem unsympathetic, but honestly, I don't have time to try to read such an unformatted batch of code like that. I would expect that others have the same problem, explaining why you haven't gotten any responses. What you posted would give ME a headache, too. Find a "pretty print" utility to format it so that a human can read it with some clarity, and you may find the answer yourself, or if not, post it here (within "Code" tags!) and someone is more likely to be willing to read it and offer you some help.

Re: checkbox *2 columns off* ????

Posted: Fri Oct 17, 2008 9:17 pm
by keane7
califdon wrote:I really don't want to seem unsympathetic, but honestly, I don't have time to try to read such an unformatted batch of code like that. I would expect that others have the same problem, explaining why you haven't gotten any responses. What you posted would give ME a headache, too. Find a "pretty print" utility to format it so that a human can read it with some clarity, and you may find the answer yourself, or if not, post it here (within "Code" tags!) and someone is more likely to be willing to read it and offer you some help.
Oh, its cool, i understand. This code is doing my head in, i never thought it would be so hard for a box to select all the boxes below it within a column.