0

Last time i ask this question : javascript/jquery clone not working in dropdown list

every thing is working but now i added this <input type="date"> in the form. When cloning, the date is not being copied.

apart from this, i want the date to be copied and to be incremented one day for each clone. this is my function

for (var i = 0; i < rows; i++) {
        lastRow = $('#dataTable tr').last().html();
        $('#dataTable tr:last').after('<tr>'+lastRow+'</tr>');
        $('#dataTable tr:last').find('select').each(function(){
            var this_select=$(this);
            this_select.val(this_select.closest('tr').prev().find('td:eq('+this_select.closest('td').index()+')').find('select').val())
        });
    }
Community
  • 1
  • 1
Shauzab Ali Rawjani
  • 256
  • 1
  • 4
  • 16

1 Answers1

0

You can use clone() for this like,

for (var i = 0; i < rows; i++) {
    $lastRow = $('#dataTable tr:last').clone();
    $lastrow.find('select').each(function(){
        var this_select=$(this);
        this_select.val(this_select.closest('tr').prev().find('td:eq('+this_select.closest('td').index()+')').find('select').val())
    });
    $('#dataTable tr:last').after($lastrow);
}
Rohan Kumar
  • 40,431
  • 11
  • 76
  • 106