Adkadk
Adkadk

Reputation: 3

form submit inside bootstrap modal form to do an appendTo html table

heres the DEMO, Heres the demo ttp://jsfiddle.net/2GfhF/7

form action error? when I try it on localhost, val from from shows in a new row but dissapear afterwards. any sols?

Upvotes: 0

Views: 77

Answers (2)

Bhavin Solanki
Bhavin Solanki

Reputation: 4818

Hi you have to add return false on form submit, because it reload page.

OR you can add following code after .appendTo() call

$('.form-actions button[type="button"]').trigger('click');//to close modal

    return false;// stop page to reload

New Updated full script

$("#save_add_new_row").click(function () {
    var $tr = $('<tr />');
    $tr.append($("<td />", {
        text: $("#category_selection_list").val()
    }));
    $tr.append($("<td />", {
        text: $("#curriculum_name").val()
    }));
    $tr.append($("<td />", {
        text: $("#curriculum_textarea").val()
    }));
     if($("#checkbox_status").prop('checked') == true){
    $tr.append("<td style='text-align:center;' class='label-success' >Active</td>");
    }else{
        $tr.append("<td style='text-align:center;' class='label-danger' >Inactive</td>");

    }
    //$tr.append($("<td />", { text: $(".test5:checked").val() }))
    $tr.appendTo($("#sample_editable_1"));
$('.form-actions button[type="button"]').trigger('click');//to close modal

    return false;
});

Upvotes: 1

Bhavin Solanki
Bhavin Solanki

Reputation: 4818

if checked, it equals to text active , if not equals to inactive inside the:

You can use the code

 if($("#checkbox_status").prop('checked') == true){
    $tr.append($("<td />", {
        text:  'Active'
    }))
    }else{
                $tr.append($("<td />", {
        text:  'Inactive'
    }))

Upvotes: 0

Related Questions