1
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 fields (Code|Description|Qtd) table tb1 to the table tb2 as soon as the checkbox of the "Send" column is marked in the table tb1? I also need that on the table tb2 an input is generated to fill in an observation.
I tried using the following jQuery code, but it just copies the values and puts 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 checkbox "Send" marked.
2-The field ONE should not be sent to table 2.
3-It must be generated in the table 2, an "Observation" input for each cloned line.
4-Once the checkbox is unchecked on table 1 the corresponding line in table 2 must be removed.
I made an answer, but, I was in doubt on some points, it is to clone the line or remove and add on the other?
– novic