I have some probelm about insert child data (C,E,D). if component parent is not checked, child data (C,E,D are disabled) for now the js cannot work for first load page, only on when i change the parent checkbox.
this is screenshot for preview http://s18.postimg.org/ghy6gfg9l/preview.jpg
$(document).ready(function() {
$("input[name^='mod']").change(function() {
if($(this).attr("checked")) $(this).closest("tr").children().children().removeAttr("disabled")
else {
//remove checks
$(this).closest("tr").children().children().removeAttr("checked")
//make all disabled
$(this).closest("tr").children().children().attr("disabled","true")
//but fix me
$(this).removeAttr("disabled")
}
})
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<form method="post"/>
<table>
<tr>
<th>No</th>
<th colspan="2" align="left">component privilege</th>
<th>C</th>
<th>E</th>
<th>D</th>
</tr>
<tr>
<tr>
<td align='center' width="7">1</td>
<td width="10"><input type='checkbox' name='mod[]' value='1'></td>
<td>Posts</td>
<td><input type='checkbox' name='C[]' /></td>
<td><input type='checkbox' name='E[]' /></td>
<td><input type='checkbox' name='D[]' /></td>
</tr>
<tr>
<td align='center' width="7">2</td>
<td width="10"><input type='checkbox' name='mod[]' value='2'></td>
<td>category</td>
<td><input type='checkbox' name='C[]' /></td>
<td><input type='checkbox' name='E[]' /></td>
<td><input type='checkbox' name='D[]' /></td>
</tr>
<tr>
<td align='center' width="7">3</td>
<td width="10"><input type='checkbox' name='mod[]' value='3' ></td>
<td>users</td>
<td><input type='checkbox' name='C[]' /></td>
<td><input type='checkbox' name='E[]' /></td>
<td><input type='checkbox' name='D[]' /></td>
</tr>
<tr>
<td></td>
<td><button type="submit" name="save">save</button></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
</form>
and this is my sample php code for insert the data,, i will if component parent is checked and child checkbox checked too, the child checkbox have value Y, else N. Please help,, im soory for my english..
if (isset($_POST['save'])) {
for ($i = 0; $i < 3; $i++) {
$mod = $_POST['mod'];
$c = $_POST['C'];
$e = $_POST['E'];
$d = $_POST['D'];
if (isset($mod[$i])) {
if (isset($c[$i]) && isset($e[$i]) && isset($d[$i])) {
echo '<br/>'.$mod[$i].' : Y-Y-Y'; //C,E,D checked
} else if (isset($c[$i]) && isset($e[$i])) {
echo '<br/>'.$mod[$i].' : Y-Y-N'; C,E checked, D no
} else if (isset($c[$i])) {
echo '<br/>'.$mod[$i].' : Y-N-N'; //only C was checked
} else {
echo '<br/>'.$mod[$i].' : N-N-N'; //only component
}
} else {
echo '<br/> NNNN'; //not all
} //end isset cek mod
} //end for
} //end isset save
</div>