hello,

i am doing check all checkboxes in a single click. i have multiple groups is there in one page. but first block is working. from second block onwords it is not working. plz help me. here is my code

<script type="text/javascript">
function checkstate(chkname,k)
{
//alert(chkname);
//var chk="chkall"+k;
//alert(document.getElementById("chkall"+k+"[]").checked)


	if(document.getElementById("chkall"+k+"[]").checked)
	{
	//alert("1");
		checkall("compdetails",chkname,1);
		
	}
	if(!(document.getElementById("chkall"+k+"[]").checked))
	{
	//alert("0");
		checkall("compdetails",chkname,0);
	}
}
function checkall(FormName, FieldName, CheckValue)
{
alert(FieldName);
	if(!document.forms[FormName])
	return;
		alert(document.forms["compdetails"].elements["modid2"]);
	var objCheckBoxes = document.forms[FormName].elements[FieldName];
	alert(objCheckBoxes);
	if(!objCheckBoxes)
	{
	alert("dghdgh");
		return;
		}
	var countCheckBoxes = objCheckBoxes.length;
	alert(countCheckBoxes);
	if(!countCheckBoxes)
		objCheckBoxes.checked = CheckValue;
	else
		// set the check value for all check boxes
		for(var i = 0; i < countCheckBoxes; i++)
			objCheckBoxes[i].checked = CheckValue;
}	
function checkval(chkname1,m)
{
//alert(chkname1);
	var allchkbox=document.forms['compdetails'].elements[chkname1];
	//alert(allchkbox);
	var countallchkbox = allchkbox.length;
	alert(countallchkbox);
	for(var i = 0; i < countallchkbox; i++)
		{
		//alert(i);
			if(allchkbox[i].checked == 0)
			document.getElementById("chkall"+m+"[]").checked=0;
		}
}	
</script>
<div class="wrapper">
<h3>Compatible Products</h3>
<?
$sMname=mysql_query("select * from manufacturers where status=1");
$count=mysql_num_rows($sMname);
if($count>0)
{
$i=1;
while($fMname=mysql_fetch_array($sMname))
{
?>
<form name="compdetails" action="" method="post" onSubmit="">
  <div class="compatibleitem">
    <div class="comp_title">
    <? echo"chkall".$i; ?> <input type="checkbox" name="chkall<?=$i?>[]" id="chkall<?=$i?>[]" onclick="checkstate('modid<?=$i?>[]',<?=$i?>);" />
      <?=$fMname['companyname']?></div>
    <div class="comp_items">
<?
$sModname=mysql_query("select * from models where company_id=$fMname[auto_id] and status=1");
$modcount=mysql_num_rows($sModname);
if($modcount>0)
{

while($fModname=mysql_fetch_array($sModname))
{
?>	
      <ul>
        <li>
		<input type="hidden" name="chk1[]"  id="chk1" value="<?=$fModname['auto_id']?>">
         <? echo "modid".$i; ?> <input type="checkbox" name="modid<?=$i?>[]" onClick="checkval('modid<?=$i?>[]',<?=$i?>)" id="chk" value="<?=$fModname['auto_id']?>" align="left"/><?=$fModname['modelno']?></li>
       </ul>
	   <?
	   
	   }
	   
	   }
	   else
	   {
	   ?>
	   <p>There Is no Models.</p>
	   <?
	   }
	   ?>
    </div>
  </div>
  </form>
  <?
  $i++;
  
  }
  }
  else
  {
  ?>
  <p>There Is No Manufacturers.</p>
  <?
  }
  ?>
</div>
<form name ="mylist">
<?

for($i=1;$i<=4;$i++)
{
for($j=1;$j<=4;$j++)
{
?>
  <input type="checkbox" name="checkGroup<?=$j?>" value ="<?=$j?>"><?=$j?><br>
  <?
  }
  ?>
 
  <input type="checkbox" name="all<?=$i?>" onClick="checkAll(checkGroup<?=$j?>,this)">Check/Uncheck All<br>
  <?
  }
  ?>
</form>

how to check each and every category individually?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.