# Multiply two fields and give total value

Home Forums Quform WordPress Multiply two fields and give total value

This topic is: resolved
Viewing 3 posts - 1 through 3 (of 3 total)
• Author
Posts
• #34987
Dylan Scholtz
Participant

Hi

I am trying to get 2 numeric value fields multiply and give a sqm total.

I am currently using the below script from other topics but it only adds up.

jQuery(function (\$) {
var calculate = function () {
var total = 0;

// A text input field with numeric value
var val4 = \$(‘.quform-field-3_38’).val();
if (val4 && val4.length && \$.isNumeric(val4)) {
total += parseFloat(val4);
}
// A text input field with numeric value
var val4 = \$(‘.quform-field-3_40’).val();
if (val4 && val4.length && \$.isNumeric(val4)) {
total += parseFloat(val4);
}

// Display the result to the user (optional)
\$(‘#form-total’).text(‘Total: sqm’ + total) ;

// Set the value of the hidden field (optional)
\$(‘.quform-field-3_111’).val(‘sqm’ + total).triggerHandler(‘change’);
};

calculate();

// Recalculate when these text input fields are changed
\$(‘.quform-field-3_38, .quform-field-3_40’).on(‘keyup blur’, calculate);
});

I saw the one topic of how to multiply by 3 but I want the fields to multiply each other and give a total.

And then another thing that I want to accomplish is to add a minimum limit to the total value field for example.

The fields that multiplies gives a total sqm and that total needs to be above 450sqm and if it is not above that value the user must not be able to submit the form.

And then one last thing I want is to get the ‘sqm’ behind the total value please if possible.

#34990
Ally
Support Staff