Home › Forums › Quform WordPress › Calculation of three select menu values.
- This topic has 1 reply, 2 voices, and was last updated 5 years, 10 months ago by Ally.
- AuthorPosts
- June 14, 2018 at 9:37 am #26056EitelParticipant
Good day Support Team
I have created a multi-page form with 3 select menus on page 2. The total amount of the 3 select menus must be added in order to display the total. The 3 menu id’s are .quform-field-1_3, .quform-field-1_121 and
.quform-field-1_34I have created the html for the “Form Total” on the page and it shows Total: R0. (R is the currency symbol)
The value of the items in the first select menu are 0, 705, 907 etc.
In order to do the calculations I have added the following JavaScript in the Settings.
jQuery(function ($) {
var calculate = function () {
var total = 0;// Check the selected option of a select menu
var val1 = $(‘.quform-field-1_3’).val();
if (val1 == ‘Option 0’) {
total +=0;
} else if (val1 == ‘Option 1’) {
total +=705;
} else if (val1 == ‘Option 2’) {
total +=907;
}// Check the selected option of a select menu
var val1 = $(‘.quform-field-1_121’).val();
if (val1 == ‘Option 0’) {
total += 750;
} else if (val1 == ‘Option 1’) {
total += 850;
} else if (val1 == ‘Option 2’) {
total += 950;
}// Check the selected option of a select menu
var val1 = $(‘.quform-field-1_34’).val();
if (val1 == ‘Option 0’) {
total += 0;
} else if (val1 == ‘Option 1’) {
total += 0;
} else if (val1 == ‘Option 2’) {
total += 950;
}// Display the result to the user
$(‘#form-total’).text(‘Total: R’ + total);// Set the value of the hidden field
$(‘.quform-field-1_9’).val(‘R’ + total);
};// Calculate on page load
calculate();// Recalculate when these select menus are changed
$(‘.quform-field-1_3, .quform-field-1_121’).change(calculate);// Recalculate when these select menus are changed
$(‘.quform-field-1_3, .quform-field-1_34’).change(calculate);// Recalculate when these select menus are changed
$(‘.quform-field-1_3, .quform-field-1_4’).change(calculate);
});No calculations are however made on the actual WordPress page. Kindly have a look at my JS and help me as I am not experienced in JS.
I am attaching a screenshots of the 3 select menus as I am not sure whether I have added the values.properly.
Thank you
Kind regards
Eitel
Attachments:
You must be logged in to view attached files.June 19, 2018 at 3:04 pm #26099AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
- AuthorPosts
- You must be logged in to reply to this topic.