0

I made a code that creates a list of multiple-checkbox from query, this code allows me to select group of choices either from the parent choice or individually everything is fine with me till the moment of echo the selected check-boxes in the input textbox, i don't know how to do that!

I'd like to get only the selected check-boxes of the children choices into the input text box like this name1, name2, ...etc

<input type="text" class="form-control" name="checkbox" value=""/>     
<?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 usertype = 'user' AND '".$row["mainjob"]."' = users.mainjob GROUP BY users.userjob, users.usertype");
        while ($row2 = mysqli_fetch_assoc($query2)):
            ?>
            <div class="children">
                <label><input type="checkbox" name="checkbox"/> <?php echo $row2["userjob"]; ?></label>

            <?php
        endwhile;
        ?>
    </section>
<?php endwhile; ?>

<script type="text/javascript">
    $("h3 input:checkbox").cbFamily(function (){
        return $(this).parents("h3").next().find("input:checkbox");
    });
</script>

</section>

my list of multiple checkbox is

enter image description here

mickmackusa
  • 43,625
  • 12
  • 83
  • 136
sandanet
  • 37
  • 7
  • For PHP to see an array of checkbox values come in, you need to use PHP array syntax in the `name` attribute. You also need to have a `value` attribute - ` Choice 1` – ivanivan Oct 29 '18 at 01:11
  • https://stackoverflow.com/q/12031851/2943403 – mickmackusa Oct 29 '18 at 01:47
  • Possible duplicate of [Multiple checkboxes with one name (no jquery!)](https://stackoverflow.com/questions/45758389/multiple-checkboxes-with-one-name-no-jquery) – mickmackusa Oct 29 '18 at 01:47
  • ok I've changed it to this one but still wondering how to echo the checked items of children in a textbox ! – sandanet Oct 29 '18 at 03:36

0 Answers0