Below is the code where I have a checkbox, on click of which the Name and Age field appears. Now when I click on “+ Insert row” for the second time then multiple rows are getting added than one at a time.
Please help me know where I am going wrong. Any help would be appreciated. Thanks in advance
<div align="left">
<input type="checkbox" name="hlt" value="hlt"> Home Leave Travel</input>
</div>
<div class="col-md-4" data-box="box" style="display: none;" id="hlt">
<br>
Name: <input type="text" name="name" class="form-control"/><br>
<br>
Age: <input type="number" name="age" class="form-control" min="1" max="100"><br>
<p id="addnew" >
<a href="javascript:void(0)" class="addlinks" onclick="addhlt()"> + Insert Row </a>
</p>
</div>
function addhlt()
{
//jsTravelDet
$("#hlt").clone().attr('id', function(_, id) { return id + hltRowCount }).find("input, select").each(function() {
$(this).val('').attr('id', function(_, id) { return id + hltRowCount });
$(this).find("option:first").attr("selected", true);
}).end().appendTo("#hlt");
hltRowCount++;
}