Question : Jquery help

I have number of rows. On each row I have select all checkbox . By clicking on this checkbox all the the checkboxes on THIS row must be checked .

How can I do this?
I have the sample code but does not seems to be working ?

function checkAll(chk) {
                                                      if (chk.checked) {
                                                             $("##" + chk.id).parent("tr").attr('checked', true);
                                                      }else{
                                                            $("##" + chk.id).parent("td").parent("tr").attr('checked', false);
                                                            }
                                                      }

Answer : Jquery help

Check the following test page :

We set a class << topCheckbox >> for each first checkbox on each row.

And we use the class : $(".topCheckbox").click(function() {
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<script language="javascript">
	$(document).ready(function() {
		$(".topCheckbox").click(function() {
		   if( $(this).is(":checked") ) {
			   $(this).parents("tr").find("input[type='checkbox']").each(function() { $(this).attr("checked", true) });
		   }
		   else {
			   $(this).parents("tr").find("input[type='checkbox']").each(function() { $(this).attr("checked", false) });
		   }
		});
	});
</script>
</head>
<body>
<table>
<tr><td><input type="checkbox" class="topCheckbox" /></td><td><input type="checkbox" /></td><td><input type="checkbox" /></td><td><input type="checkbox" /></td></tr>
<tr><td><input type="checkbox" class="topCheckbox" /></td><td><input type="checkbox" /></td><td><input type="checkbox" /></td><td><input type="checkbox" /></td></tr>
<tr><td><input type="checkbox" class="topCheckbox" /></td><td><input type="checkbox" /></td><td><input type="checkbox" /></td><td><input type="checkbox" /></td></tr>
<tr><td><input type="checkbox" class="topCheckbox" /></td><td><input type="checkbox" /></td><td><input type="checkbox" /></td><td><input type="checkbox" /></td></tr>
<tr><td><input type="checkbox" class="topCheckbox" /></td><td><input type="checkbox" /></td><td><input type="checkbox" /></td><td><input type="checkbox" /></td></tr>
</table>
</body>
</html>
Random Solutions  
 
programming4us programming4us