Problem with multiple checkbox
        Posted  
        
            by 
                Pushpendra
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Pushpendra
        
        
        
        Published on 2011-02-09T15:03:20Z
        Indexed on 
            2011/02/09
            15:25 UTC
        
        
        Read the original article
        Hit count: 259
        
I am using a checkbox that has the name selectedids[], and I am trying to select all checkbox with the JavaScript but the code is not working. However, when I change the name of checkbox to selectedids it works but I can't do so because I need all the ids that are selected on the POSTED page.
The checkbox is as follow.
foreach($rows as $row)
{
<input type="checkbox" name="selectedids[]" value="<?php echo $row['id']; ?>" class="checkbox" />
........
........
}
And the Java-script function is as follow
function SetAllCheckBoxes(CheckValue)
{
    var CheckValue=true;
    if(!document.forms['main'])
        return;
    var objCheckBoxes = document.forms['main'].elements['selectedids[]'];
    if(!objCheckBoxes)
        return;
    var countCheckBoxes = objCheckBoxes.length;
    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;
}
Please help me.
Thanks in advance..
© Stack Overflow or respective owner