hello,


i am doing oneconcept. i have number of categories and number of subcategories is there.
i gave one checkbox to each and every category. and checkbox to each subcategory. when i select category it automatically checks all its subcategory.
actually i am fetching categorys from database. here is my code.
PHP 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;
        
    var objCheckBoxes = document.forms[FormName].elements[FieldName];
    alert(objCheckBoxes);
    if(!objCheckBoxes)
        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">
      <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="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>
it is working fine for checkbox of firstcategory. but from second category i put on alert below statement it returns undefined. but it is working fine for first category.
PHP Code:
alerts(document.forms[FormName].elements[FieldName]); 
undefined. where is the problem?