hi! i don't have problem in checking all checkbox but if i uncheck the checkbox the id=cball(my main checkbox of all),
the sub don't follow the main(id=cball);

here's my code for jquery:

$(document).ready(function(){
      
	  $("#cball").click(function(){
	  
	    $("tr [id=cbmessage]").attr("checked","checked");
	  
	  },function()
	  {
	  	 $("tr [id=cbmessage]").attr("checked","");
	  });
   
   
   
   });

html code:

<input type="checkbox" name="cball" id="cball"  />


<input type="checkbox" name="cball" id="cbmessage"  /><br>
<input type="checkbox" name="cball" id="cbmessage"  />

jQuery's "click" event only accepts one event handler.

In the following code snippet I'm using the "click" event to check and uncheck every checkbox not identified as "cball".

$(document).ready(function() {
	$('#cball').click(function(){
		if ($(this).is(':checked')) {
			$('input:checkbox:not(#cball)').attr('checked', true);
		} else {
			$('input:checkbox:not(#cball)').attr('checked', false);
		}
	});
});

The "toggle" event accepts multiple event handlers.

$(document).ready(function() {
	$('#cball').toggle(function(){
		$('input:checkbox:not(#cball)').attr('checked', true);
	}, function() {
		$('input:checkbox:not(#cball)').attr('checked', false);
	});
});

Both methods accomplish the same task.

ok! i will try this at home. i think this will work. how about if i click one of the id=cbmessage? how can i get the value of each id=cbmessage?

ID can only refer to a single element you cant have two elements id='cbmessage' thats why your script is failing
you can foreach on getelementbyname

id for single element. how about class?

A class is limitless. I would suggest using a class amongst your checkboxes.

thank you. now i know the difference between the id and the class.

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.