0

I've this to append dynamically created checkbox in each row of table. I don't know why this is not working.

<script>
    $(".ajaxcall").click(function () {
//        $("#subcattablerows").remove();
        $("#subcattable tbody").empty();
        var cat_id = $(this).data("catid");
//        alert(cat_id);
        $.ajax({
            type: "POST",
            dataType: "json",
            url: "<?php echo base_url() . 'Products/getsubcat' ?>",
            data: {"cat_id": cat_id},
            success: function (result) {
//                console.log(result.result);
//                $('#result').html(Result);
                var JSONObject = result.result;
                for (var key in JSONObject) {
                    if (JSONObject.hasOwnProperty(key)) {
                        $('#subcattable').append(
                                "<tr style='width: 100%; display: inline-table;'>"
                                + "<td>"+"<input type='checkbox'>" + JSONObject[key]["subcatname"] + "</td>"
                                + "</tr>"
                                );
                        console.log(JSONObject[key]["subcatname"]);
                    }
                }
            }
        });
    });
</script>
Tom Aranda
  • 5,919
  • 11
  • 35
  • 51
Mobeen Sarwar
  • 514
  • 5
  • 23
  • Can you setup jsfiddle? It seems you want to append new to each existing in the table but somehow you append to whole ?
    – mybrave Jan 10 '18 at 12:18
  • https://jsfiddle.net/cxvnp12h/ – Mobeen Sarwar Jan 10 '18 at 12:28
  • There are two tables left and right. When i click on of left table, data loaded in right table with checkboxe with each entry. – Mobeen Sarwar Jan 10 '18 at 12:30
  • I do recommend to review e.g. https://stackoverflow.com/questions/171027/add-table-row-in-jquery or https://www.tutorialrepublic.com/codelab.php?topic=faq&file=jquery-append-and-remove-table-row-dynamically. both should give you enough ideas on what is wrong. – mybrave Jan 10 '18 at 13:45
  • Thanks @mybrave i got the issue – Mobeen Sarwar Jan 10 '18 at 13:58

0 Answers0