mardi 17 novembre 2015

ajax issue related to checkbox

this is my ajax code

 $(document).ready(function (e) {
            $('.checkbox').click(function (e) {

                $(event.currentTarget).val($(event.currentTarget)[0].checked);
                var Curl = $('#chkform').attr("action");
                var val = $('.checkbox:checked').val();
                alert(val);
                $.ajax({
                    url: Curl,
                    type: "POST",
                    dataType: "json",
                    data: {
                        chk: val
                    },
                    contentType: false,
                    cache: false,
                    processData: false,
                    success: function (result) {
                        alert(result);
                        var l = result.length;
                        for (var i = 0; i < l; i++) {
                            $('#table').append($('<tbody>')
                                    .append($('<tr>')
                                            .append('<td>' + result[i].id + '</td>')
                                            .append('<td>' + result[i].product_name + '</td>')
                                            .append('<td>' + result[i].product_description + '</td>')
                                            .append('<td>' + result[i].product_price + '</td>')
                                            .append('<td>' + result[i].product_pieces + '</td>'))
                                    );

                        }

                    },
                    error: function () {
                    }
                });
            });
        });
 <form method="post" id="chkform" action="<?php echo site_url('form_sort/sorting') ?>" >
        <input type="checkbox" name="chk" value="5000-6999" class="checkbox">5000-6999<br>
        <input type="checkbox" name="chk" value="7000-8999" class="checkbox">7000-8999<br>
        <input type="checkbox" name="chk" value="9000-12999"class="checkbox">9000-12999<br>


    </form>

this is my controller code

    $chkvalue = $this->input->post("chk");
    echo $chkvalue;

i can't get checkbox value in $chkvalue, when i click on checkbox alert give me null as a result i want result is checkbox value because i echo $chkvalue.




Aucun commentaire:

Enregistrer un commentaire