jquery Row id change on Duplicate button click

130 views Asked by At

I have a form to be submitted to a php page. Each row has a checkbox and if the checkbox[es] is checked that rows get duplicated upon the button click event. How do i change the row id for the newly appended row? (it fails to work when multiple rows are duplicated ).Code below

$("#DuplicateRow").click(function () {
    var checkboxValues = [];
    $('input[class="child"]:checked').each(function(){
    var $chkbox=$(this);
    var row=( $(this).closest('tr').prop('rowIndex') );
    //alert(row);
    var new_row=row+1;
    var xx="row"+new_row;
    //alert (xx);
    var $actualrow = $chkbox.closest('tr');                                       
    var $clonedRow = $actualrow.clone();
    $clonedRow.attr("id", xx);
    $clonedRow.find("select").each(function(i){
    this.selectedIndex = $actualrow.find("select")[i].selectedIndex;
    })
    $chkbox.closest('#tabletomodify').append( $clonedRow );
    } );} );
0

There are 0 answers