php - Make checkbox checked for each table -
i have lot of tables database , show users. here sample table likes. sample here. once user checked each table bottom right check box, whole check box table checked.
php function call each table database
function base_generategrouprulechecklist($gid) { //connect database base_connectdatabase(); $count = 0; //get base_modules id $getparentmodulesql = base_executesql("select * base_parent_modules order base_pmod_sort_by" ); $count1 = base_num_rows($getparentmodulesql); while($parentmoduledata_row = base_fetch_array($getparentmodulesql)) if ($count1!= 0) { //show category echo "<table style=\"border-collapse: collapse\" width=\"100%\" class=\"permission\">"; echo "<tr>"; echo "<th class=\"centertext\">".$parentmoduledata_row['base_pmod_name']."</th>"; echo "<th align=\"center\"><img src=\"". base_img_icon_view ."\" style=\"width:25px; height:25px\" title=\"view permission\" /></th>"; echo "<th align=\"center\"><img src=\"". base_img_icon_add ."\" style=\"width:25px; height:25px\" title=\"add permission\" /></th>"; echo "<th align=\"center\"><img src=\"". base_img_icon_edit ."\" style=\"width:25px; height:25px\" title=\"update permission\" /></th>"; echo "<th align=\"center\"><img src=\"". base_img_icon_delete ."\" style=\"width:25px; height:25px\" title=\"delete permission\" /></th>"; echo "</tr>"; $getmodulesql = base_executesql("select * base_modules, base_group_details base_mod_parent = ".$parentmoduledata_row['base_pmod_id']." , base_gpd_gp = ".$gid." , base_gpd_mod = base_mod_id order base_mod_sort_by" ); while($moduledata_row = base_fetch_array($getmodulesql)) if (base_num_rows($getmodulesql)!= 0) { if ($moduledata_row["base_gpd_rule_view"] == "on" ) { $view = "checked"; }else { $view = ""; } if ($moduledata_row["base_gpd_rule_add"] == "on" ) { $add = "checked"; }else { $add = ""; } if ($moduledata_row["base_gpd_rule_edit"] == "on" ) { $edit = "checked"; }else { $edit = ""; } if ($moduledata_row["base_gpd_rule_delete"] == "on" ) { $delete = "checked"; }else { $delete = ""; } //show module $count +=1; echo "<tbody>"; echo "<tr>"; echo "<td>". $count .". ".$moduledata_row['base_mod_name']."</td>"; echo "<td align=\"center\"><input type=\"checkbox\" value=\"on\" name=\"gp_mod_1_".$moduledata_row['base_mod_id']."\" ".$view." /></td>"; echo "<td align=\"center\"><input type=\"checkbox\" value=\"on\" name=\"gp_mod_2_".$moduledata_row['base_mod_id']."\" ".$add." /></td>"; echo "<td align=\"center\"><input type=\"checkbox\" value=\"on\" name=\"gp_mod_3_".$moduledata_row['base_mod_id']."\" ".$edit." /></td>"; echo "<td align=\"center\"><input type=\"checkbox\" value=\"on\" name=\"gp_mod_4_".$moduledata_row['base_mod_id']."\" ".$delete." /></td>"; echo "</tr>"; } echo "<tr align='right'>"; echo "<td colspan='5'><input type=\"checkbox\" id='allcb' name='allcb'/></td>"; echo "</tr>"; echo "</tbody>"; echo "</table><br />"; } return $count; //close database base_closedatabase(); }
here sample result want. jsfiddle
source : stackoverflow
you can use change event handler listen change event of checkbox in last tr of each table set checked status checkbox elements in table state of changed checkbox
//change event handler checkbox in last tr $('table tr:last-child input:checkbox').change(function(){ //use closest find table containing changed checkbox , set checked value each checkbox in table new status $(this).closest('table').find('input:checkbox').prop('checked', this.checked) })
demo: fiddle
Comments
Post a Comment