Try this:

<script type="text/javascript">

$(document).ready(function() {

   $('#checkAll').click(function() {

      $('input:checkbox').each(function() {

         if   (  $(this).hasClass('state_abbr')  )
              {  $(this).attr('checked', 'checked'); }

      });
   });
});

</script>

HTML:

<input id="id" class="state_abbr" type="checkbox" name="name" >GA<br>
<input id="id" class="state_abbr" type="checkbox" name="name" >FL<br>
<input id="id" class="state_abbr" type="checkbox" name="name" >TN<br>
<input id="id" class="country_abbr" type="checkbox" name="name" >USA<br>
        
<br>
<br>
        
<a id="checkAll" href="" onClick="return false;">check all boxes</a>



-----Original Message-----
From: Greg Morphis [mailto:[email protected]] 
Sent: Friday, April 15, 2011 12:20 PM
To: cf-talk
Subject: SOT: jQuery help


I have a page with a bunch of groups of checkboxes.
I'm trying to add functionality so the user can do a "check all" and
it would in turn check all the boxes.

I found this via a google search but it's selecting EVERY checkbox on
the page, not just the ones names "state_abbr".
function jqCheckAll2( id, name )
{
   $("INPUT[@name=" + name + "][type='checkbox']").attr('checked',
$('#' + id).is(':checked'));
}
</script>


and...
<input type="checkbox" name="checkAllStates" id="checkAllStates"
onclick="jqCheckAll2( this.id, 'state_abbr' )"/> Check All States

The other groups and correctly names com_id, workgroup_id, etc.. so
why is jQuery checking them?

Thanks!



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:343757
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm

Reply via email to