Monday, April 10, 2017

get checked, checkbox in laravel controller from view

I have multiple buttons with single form, so i create route dynamically using jquery. Try to get all checked checkboxed my code is as below:

view

 
    <div class="col-md-10 pull-right" style="margin-top:-20px;">
        <ul class="nav navbar-nav pull-right sub-nav">
            <li>
                <a> <input type="submit" name="add-to-cart" id="abc" class="btn btn-link" value="ADD TO CART"></a>
            </li>
            <li>
                <a><input type="submit" class="btn btn-link" name="stock-file" value="STOCK FILE"></a>
            </li>
            <li>
                <a><button type="submit" class="btn btn-link">COPY DETAILS</button></a>
            </li>
         </ul>
    </div>
    <table id="main" class="table table-bordered">
        <thead>
            <tr>
                <th>
                    <input type="checkbox" value="">
                </th>
                <th>purchase date</th>
                <th>lab</th>
                <th>report</th>
                <th>stock id</th>
                <th>loc</th>
                <th>buy</th>
                <th>shape</th>
                <th>size</th>
                <th>color</th>
                <th>clarity</th>
                <th>cut</th>
                <th>polish</th>
                <th>sym</th>
                <th>flr</th>
                <th>comment</th>
            </tr>
        </thead>
        <tbody >
            @foreach($stone_details as $stone)
                <tr>
                    <td>
                        <input type="checkbox" name="abc[]" id="" value="">
                    </td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                </tr>
            @endforeach
        </tbody>
    </table>



<script type="text/javascript">
    $('document').ready(function () {
        var baseUrl = "";
        $('form :submit').on('click', function(event){

            var a = $(this);
            var form = $('form');
            var action = a.attr('id');

            form.attr('action', baseUrl + '/stock_sell/' + action);
            form.submit();
        });
    });    
</script>

controller

public  function abc(){
    echo "<h1>yoajdslkf </h1>";
    $friends_checked = Input::get('abc');
    if(is_array($friends_checked))
    {
        print_r( $friends_checked);
    }
}

Above is my code of view and controller, if i used simple action then it work fine and display all checked checkboxes. please help me get list of all checked checkbox id.



via HirenMangukiya

Advertisement