views:

50

answers:

1

Any idea why this code is failing? I'm doing the exact same thing somewhere else, except I'm using a DIV with an ID for my selector. This time I needed to use a "CLASS name" as my selector, but it doesn't work. All I want to do is check one checkbox and have it check all the checkboxes that have the same class name. Any help is appreciated, or any other ways of accomplishing the same thing in a better way are appreciated.

Thanks.

Javascript FUNCTION:

function jqCheckAll_byClass(class_name, name, check_me)
{
   if (check_me == false)
   {
      $("." + class_name + " INPUT[@name=" + name + "][type='checkbox']").attr('checked', false);
   }
   else
   {
       $("." + class_name + " INPUT[@name=" + name + "][type='checkbox']").attr('checked', true);
   }
}

ONCLICK EVENT:

<input type="checkbox" onclick="jqCheckAll_byClass('5_arch_chbx','5_archive_chbx', this.checked );" title="Check All" class="a_hand">

HTML:

<input type="checkbox" class="5_arch_chbx input_editible" name="5_archive_chbx" id="2087archive_chbx_id">
+2  A: 

Remove onclick from HTML and try this one. I have also provided an id for the check all checkbox.

<input type="checkbox" id="chkAll" title="Check All" class="a_hand">

$(function(){
    $("#chkAll").click(function(){
        $(":checkbox.5_arch_chbx").attr ( "checked", $(this).attr("checked") );
    });
});
rahul
Rahul, thanks for your tip above with removing the "@". The reason I had it working before is I was using a div id as part of the selector and that div wrapped a table. Once I added a div and wrapped it around the table (instead of inside the table) it started checking all the boxes. However until I removed the "@" it would select all the boxes, instead of just the boxes the selector was told to select. Thanks for your help
Ronedog