I have a field where textboxes are added dynamically using jQuery. The problem is I have other fields on that page which is mandatory to fill, so if a user forgets to fill a mandatory field the page refreshes and the dynamically added textboxes disappears, how should I prevent this to happen?
Would appreciate if someone could help me out, thanks.
<script type="text/javascript">
$('#insert-line-button').on("click", function(){
var noOfRows = 1;
for(var i = 0; i < noOfRows; i++){
$('#myTable').append("<tr style='height: 5rem;'><td><input type='text' name='input[]' " +
"class='form-control'/></td><td> </td><td><input type='button' value='x' " +
"id='deleteRowButton' class='btn btn-danger'/></td></tr>")
}
});
$("#myTable").on('click', 'input[id="deleteRowButton"]', function(event) {
$(this).parent().parent().remove();
})
</script>