Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

javascript checkbox toggle with PHP not working for array 1

Status
Not open for further replies.

webslinga

Programmer
Jun 20, 2006
55
US
Hi all,
I have a javascript function such as this:
Code:
function checkAll(checkName, exby)
{
	document.write(checkName)
	document.write(exby)
  for (i = 0; i < checkname.length; i++)
  	checkname[i].checked = exby.checked? true:false
}


And my php script is like this:
Code:
<table border=0>
<tr><th colspan="2">[b]<input type="checkbox" name="all" onClick="checkAll(document.doAssignRolesForm.credID,this)">Check/Uncheck All[/b]</th><th colspan=<?php echo $numColsspan ?>>Role</th></tr>

	$count = 0;
	foreach($Roles as $role){ ?>
	<?php if(in_array($role->getCredUnid(), $credBank)){?>
	<?php if(($count % $numCols) == 0){?>
	<tr>
	<?php } ?>
	<td><?php [b]echo checkbox_tag('credID[]', $role->getCredUnid(), true); [/b]?></td>
	<td><?php echo $role->getDescription();?></td>
	<?php $count++; ?>
	<?php if(($count % $numCols) == 0){?>
	</tr>
	<?php } ?>
	<?php }
	else { ?>
	<?php if(($count % $numCols) == 0){?>
	<tr>
	<?php } ?>
	<td><?php echo checkbox_tag('credID[]', $role->getCredUnid(), false); ?></td>
	<td><?php echo $role->getDescription(); ?></td>
	<?php $count++; ?>
	<?php if(($count % $numCols) == 0){?>
	</tr>
	<?php } ?>
	<?php } ?>
	<?php  }


This check/uncheck box does not work and I believe the problem is because i am dynamically creating an array of checkboxes called credID. BTW if anyone doesn't understand why I subtituted a funcion checkbox_tag() for an HTML tag it is because this PHP script is following the symfony framework... I just want to know about the js problem. Any way around this? Thanks.
 
Good catch BillyRay!

Still not the result that I want though.

Code:
function checkAll(checkName, exby)
{
	document.write(checkName)
	document.write(exby)
  for (i = 0; i < checkName.length; i++)
  	checkName[i].checked = exby.checked? true:false
}
 
Oh... it was glaring me in the face. You should remove the two document.write lines. If you use document.write after a page has loaded, it will overwrite all content.

Hope this helps,
Dan

Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Sorry Dan,
I was using document.write() just for debugging purposes. I know to take them off.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top