I have added this link for adding new row to my form:
JavaScript
x
2
1
<a id="add" class="btn btn-info" style="color:white">New row</a>
2
And here is the jQuery code:
JavaScript
1
10
10
1
$(document).ready(function(){
2
var i = 1;
3
if(i == 1){
4
$('#add').click(function(){
5
i++;
6
$('#dynamic_field').append("HERE GOES THE ROW ELEMENTS");
7
});
8
}
9
});
10
And it works fine.
But I need to determine that add new row only one time and not several times.
So I tried checking if(i == 1){
in the jQuery, but does not seem to be working and user still can adds new row multiple times.
So how can I limit this to only one time?
Advertisement
Answer
you need to use one with click event:
JavaScript
1
6
1
$(document).ready(function(){
2
$('#add').one('click', function(){
3
$('#dynamic_field').append("HERE GOES THE ROW ELEMENTS");
4
});
5
});
6
This will invoke click event only once.