I have the following code:
var contador = 1;
$('.preview-add-button').click(function(){
var form_data = {};
//form_data["concept"] = $('.payment-form input[name="concept"]').val();
//form_data["description"] = $('.payment-form input[name="description"]').val();
form_data["status"] = $('.payment-form #status option:selected').text();
form_data["amount"] = parseFloat($('.payment-form input[name="amount[]"]').val()).toFixed(2);
//form_data["date"] = $('.payment-form input[name="date"]').val();
form_data["remove-row"] = '<span class="ico-cancel"></span>';
var row = $('<tr></tr>');
$.each(form_data, function( type, value ) {
$('<td class="input-'+type+'"></td>').html(value).appendTo(row);
$('<input/>').attr("type", "hidden").attr("name", "produto[]").val(form_data["status"]).appendTo(row);
$('<input/>').attr("type", "hidden").attr("name", "produto[]").val(form_data["amount"]).appendTo(row);
contador++;
});
$('.preview-table > tbody:last').append(row);
calc_total();
});
The problem is in the counter variable, instead of counting from 1 to 1 as it is in the code, when going through the loop it was sum 3 instead of 1, that is, it arrives in the loop with 1 and in the next iteration is 4, the next 7 and so on, can anyone understand why?