Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 67527

How to get values from textbox in checkbox in php

$
0
0

I have 4 checkboxes, one of them is Others have textbox, i want to get all the values that the user checked and if he checked others option to get the values from the textbox associated with Others checkbox.

HTML Code

<div class="row">
    <div class="col-sm-4">
        <label class="Modallabel">Available Products:</label>
    </div>
    <div class="col-sm-8">
        <label id="Pro_chkbox" class="checkbox-inline"><input name="check_list[]" type="checkbox" value="Cacao">Cacao</label>
        <label id="Pro_chkbox" class="checkbox-inline"><input name="check_list[]" type="checkbox" value="Coconuts">Coconuts</label>
        <label id="Pro_chkbox" class="checkbox-inline"><input name="check_list[]" type="checkbox" value="Bananas">Bananas</label><br>
        <label id="Pro_chkbox" class="checkbox-inline"><input name="check_list[]" type="checkbox" id="optcheck" value="Others">Others</label>
        <input type="text" id="Other_pro" name="otherproduct"><br>
        <label id="Note">(Separate Products with commas)</label>
    </div>
</div>

PHP Code

$checked_count = count($_POST['check_list']);

    if ($checked_count > 1)
    { 
        $productlist = implode(', ', $_POST['check_list']);
        echo $productlist;
    }
    elseif ($checked_count == 1)
    { 
        foreach($_POST['check_list'] as $selected) {
            $productlist = $selected;

            //To check if Others checkbox is checked or not to get the values in textbox
            if ($productlist == "Others")
            {
                $productlist = $_POST["otherproduct"];
            }
            echo $productlist;
        }
    }

Viewing all articles
Browse latest Browse all 67527

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>