I have a problem here that I can not solve, in the script below perform a calculation of on the marked seats, so far everything is perfect the problem and when I put a submit button to send the data and finishes clearing the field of result giving NaN Error. how can I fix this?
$(window).load(function(){
var contador = function() {
var n = $("input:enabled:checked").length;
var unchecked = 0;
var cb = $(this).index();
$("input:enabled").each(function(i) {
if ((i < cb) && !($(this).is(":checked"))) {
++unchecked;
}
})
if($(this).is(":checked")){
$('#campo').append('<div style="margin-top: 10px;"><input type="text" placeholder="Insira seu Ticket" name="tks[]" required class="created" name="check1" ></div>');
}else{
$('.created').eq($(this).index()-unchecked).remove();
}
$("#checkcount").text(n + (n === 1 ) + " Cadeiras Marcadas");
};
contador();
$("input[type=checkbox]").on("click", contador);
(function() {
var elements = document.getElementsByTagName('input');
var resultado = document.getElementById('resultado_soma');
var resultadoInput = document.getElementById('resultado_soma2');
var checkCount = document.getElementById('checkcount2');
var total = 0;
for (var i = 0; i < elements.length; i++) {
elements[i].onclick = function() {
if (this.checked === false) {
total = total - this.value;
} else {
total = total + parseFloat(this.value);
}
resultado.innerHTML = 'R$ ' + total.toFixed(2).replace(".",",");
resultadoInput.value = total.toFixed(2).replace(".",",");
checkCount.value = $("input:enabled:checked").length;
}
}
})();
});