I have a formset of inputs, I have quantity and price inputs and I want to calculate the total using jQuery for every row?
$('#step2').on("click", function() {
var total = 0;
$('.na qu').each(function() {
var prix = Number($('.na').val());
var quantite = Number($('.qu').val());
var total = prix * quantite
console.log(total)
});
alert(total);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form method="POST">
<input type="text" name="form-0-Prix_Unitaire" class="na" id="id_form-0-Prix_Unitaire">
<input type="text" name="form-0-Quantite" class="qu" id="id_form-0-Quantite">
<input type="text" name="form-0-Prix_Unitaire" class="na" id="id_form-0-Prix_Unitaire">
<input type="text" name="form-0-Quantite" class="qu" id="id_form-0-Quantite">
<input type="text" name="form-0-Prix_Unitaire" class="na" id="id_form-0-Prix_Unitaire">
<input type="text" name="form-0-Quantite" class="qu" id="id_form-0-Quantite">
<button id="step2" class="btn btn-primary">Ajouter1</button>
</form>
"Uncaught SyntaxError: Unexpected token '+='". Also, you don't do anything from stopping your form from being submitted and reloading the page. Oh and IDs must be uniquetotalto thetotalPoints.....