I have a table and I have only one row in it. I am generating rows dynamically when the Enter button is pressed. This is my code.
<table>
<thead>
<tr>
<th class="text-center">Amount</th>
<th class="text-center">Installment</th>
<th class="text-center">Source of Money</th>
</tr>
</thead>
<tbody>
<tr class="row1" id="rw1">
<td class="text-center" id="rw1cl1">
<input class="form-control" type="text">
</td>
<td class="text-center" id="rw1cl2">
<input class="form-control" type="text">
</td>
<td class="text-center" id="rw1cl3">
<input class="form-control" type="text" id="sm">
</td>
</tr>
</tbody>
</table>
JavaScript
<script type="text/javascript">
$(document).ready(function() {
$('#sm').on('keyup', function(e) {
var code = (e.keyCode ? e.keyCode : e.which);
if (code == 13) {
var cloned = $('.row1').first().clone(true);
cloned.insertAfter("#rw1");
}
});
});
</script>
I am getting cloned rows as I expected. But the problem is I am getting cloned divs with the texts which were already inserted to previous row which were used to make the clone.
Since I am new to JQuery although I am bit familiar with JavaScript, I cannot figure out how to do it. I tried several stackoverflow answers, but I ended up with no luck.
Please Help me to solve the issue. Thanks!