Reputation: 13
I'm trying to add rows selected with checkboxes from one table to other using jquery. This is in my js file
$(document).ready(function() {
$("#schedule tr input:checkbox").click(function() {
$('#results tbody').append($(this).parent('tr').clone());
$(this).parent('tr').remove();
});
});
Results are the table where the selected row is supposed to be copied to and the schedule is the source table. Is this how it's done? Thanks in advance.
Upvotes: 0
Views: 2925
Reputation: 754
You're over complicating it a little bit.
To move the row(s):
$(function(){
$(document).on("click","#submit",function(){
var getSelectedRows = $(".src-table input:checked").parents("tr");
$(".target-table tbody").append(getSelectedRows);
})
})
jsfiddle: https://jsfiddle.net/PantsStatusZero/pmdna965/
To copy the row(s):
$(function(){
$(document).on("click","#submit",function(){
var getSelectedRows = $(".src-table input:checked").parents("tr").clone();
$(".target-table tbody").append(getSelectedRows);
})
})
jsfiddle: https://jsfiddle.net/PantsStatusZero/5oomb22d/
Upvotes: 1