0

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"  />
3
Contributors
6
Replies
7
Views
7 Years
Discussion Span
Last Post by canterorist
0

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.

0

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?

Edited by canterorist: n/a

0

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

0

id for single element. how about class?

Edited by canterorist: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.