Vote count: 0
I have a page with multiple HTML forms on. I need to add up all the input values in just the one form and not all forms on the page. When the input field is typed in, it sends the data to an ajax call which works great, but the sum value is from all forms on the page, not just the one I have typed in.
$('.risk_assessments_number_input').keyup(function() {
var form = $(this).closest("form");
var ajaxurl = '<?php echo WEB_URL; ?>controllers/ajax/save_risk_assessment.php',
form_data = $(form).serialize();
var sum = 0;
$('.risk_assessments_number_input').each(function() {
sum += Number($(this).val());
});
console.log(sum);
$.post(ajaxurl, form_data, function (response) {
});
});
asked 2 mins ago
Add up values from input in one form on page
Aucun commentaire:
Enregistrer un commentaire