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

4
  • 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 - <input type=checkbox name=cb[] value="choice 1"> Choice 1 Commented Oct 29, 2018 at 1:11
  • stackoverflow.com/q/12031851/2943403 Commented Oct 29, 2018 at 1:47
  • Possible duplicate of Multiple checkboxes with one name (no jquery!) Commented Oct 29, 2018 at 1:47
  • ok I've changed it to this one <label><input type="checkbox" name="checkbox[]" value="<?php echo $row2["userjob"]; ?>"/> <?php echo $row2["userjob"]; ?></label> but still wondering how to echo the checked items of children in a textbox ! Commented Oct 29, 2018 at 3:36

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.