Reputation: 37
My question maybe has been asked many times before but i couldn't apply the given solutions on my project yet
I'm trying to post only the selected children check-boxes not the parents
my page code is:
<?php $db = mysqli_connect('localhost', 'root', '123', 'test'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="jquery.min.js"></script>
<script src="cbFamily.js"></script>
</head>
<body>
<form name="myform" method="post" action="test.php">
<section class="demo2" style="margin-top:2px;">
<?php
$query=mysqli_query($db,"SELECT * FROM tblmainjobs");
while ($row = mysqli_fetch_assoc($query)):
?>
<section>
<h3><label><input type="checkbox" /> <?php echo $row["mainjob"]; ?>
</label></h3>
<?php
$query2=mysqli_query($db,"SELECT userjob FROM users WHERE
'".$row["mainjob"]."' = users.mainjob GROUP BY users.userjob");
while ($row2 = mysqli_fetch_assoc($query2)):
?>
<div class="children">
<label><input type="checkbox" name="checkbox" value="<?php echo
$row2["userjob"]; ?>"/> <?php echo $row2["userjob"]; ?></label>
<?php endwhile; ?>
</section>
<?php endwhile; ?>
<script type="text/javascript"> <!-- this function for selecting all
children checkboxes once the parents checkbox bieng selected -->
$("h3 input:checkbox").cbFamily(function (){
return $(this).parents("h3").next().find("input:checkbox");
});
</script>
</section>
<br>
<div><input class="submit" type="submit" name="submit" value="submit"/>
</div>
</form>
</body>
</html>
my page looks like this test.php
my entire project is attached here https://www.sendspace.com/file/6ikcaa
Upvotes: 1
Views: 61
Reputation: 1431
Use array:
<input type="checkbox" name="checkbox[]" value="<?php echo
$row2["userjob"]; ?>"/> <?php echo $row2["userjob"]; ?>
notice the [] in the name attribute.
Upvotes: 1
Reputation: 13
You could use javascript to disable the "parent" checkboxes before they get posted to the server.
Add a class to your parent checkboxes to make for an easy jquery selector:
<input type="checkbox" class="parent" />
Then some javascript to disable the checkboxes:
$(".parent").prop("disabled",true);
Upvotes: 0