$(document).ready(function(){
var i = 1;
$('#add').click(function(){
i++;
$('#dynamic_field').append('<tr id="row'+i+'"><td><div class="form-group"><label for="company">Company Name:</label><input type="text" class="form-control" name="company[]"></div><div class="form-group"><label for="project">Project Name:</label><input type="text" class="form-control" name="project[]"></div><div class="form-group"><label for="role">Role:</label><input type="text" class="form-control" name="role[]"></div<div class="form-group"><label for="duration">Duration:</label><input type="text" class="form-control" name="duration[]"></div><div class="form-group"><label for="learning">Key Learning:</label><textarea class="form-control" rows="5" name="learning[]" maxlength="150"></textarea></div></td><td><br><br><br><br><br><br><br><center><button name="remove" id="'+i+'" class="btn btn-danger btn_remove">Remove</button></center></td></tr>');
});
$(document).on('click','.btn_remove', function(){
var button_id = $(this).attr("id");
$("#row"+button_id+"").remove();
});
$('#submit').click(function(){
$.ajax({
async: true,
url: "internship_details.php",
method: "POST",
data: $('#internship_details').serialize(),
success:function(rt)
{
alert(rt);
$('#internship_details')[0].reset();
}
});
});
});
This is the code for dynamic form entry. I want to set a limit that a person cannot add more than 5 i.e. I want to set the limit for value i
. How should I do that?