I have the following tables:
<html>
<table class="table table-hover" id="tb1">
<thead>
<tr>
<th class="a-center" width="60">Codigo</th>
<th class="a-left">Descrição</th>
<th class="a-center" width="40">Qtd.<br />Total</th>
<th class="a-center" width="25">UM</th>
<th class="a-center" width="25">Enviar</th>
</tr>
</thead>
<tbody>
<tr>
<td>00001</td>
<td>Produto 1</td>
<td>5</td>
<td>UN</td>
<td><input type="checkbox"></td>
</tr>
</tbody>
</table>
<br><br>
<table class="table table-hover" id="tb2">
<thead>
<tr>
<th class="a-center" width="60">Codigo</th>
<th class="a-left">Descrição</th>
<th class="a-center" width="40">Qtd.</th>
<th class="a-center" width="200">Observação</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</html>
How do I copy the Code | Description | Qtd ) fields from the tb1 table to the table tb2 as soon as the checkbox in the "Send" column is marked in the tb1 table? I also need an input to fill in an observation in the tb2 table.
I tried using the following jQuery code, but it only copies the values and puts them side by side:
jQuery("#tb1 input:checkbox").click(function(){
var html = '';
if (jQuery(this).is(":checked")){
jQuery(this).parent('td').prev('td').prev('td').prev('td').prev('td').clone().appendTo("#tb2");
jQuery(this).parent('td').prev('td').prev('td').prev('td').clone().appendTo("#tb2");
jQuery(this).parent('td').prev('td').prev('td').clone().appendTo("#tb2");
//alert(html);
} else {
var index = jQuery(this).closest("tr").attr("data-index");
var findRow = jQuery("#tb2 tr[data-index='" + index + "']");
findRow.remove();
}
});
Summarizing what the code needs to do:
1-Clone the lines that had the "Send" checkbox checked. Home 2-The UM field should not be sent to the table 2 . Home 3-Must be generated in table 2 , an input "Note" for each cloned row. 4-Once the checkbox is unchecked in table 1 the corresponding line in table 2 should be removed.