i try to make a calc process. The goal is: if one option from multi select is selected, the price is 15, if 2 options from multi select is selected, the price is 30, if 3 options from multi select is selected, the price is 45, if all option from multi select is selected, the price is 55,
Here is the code i wrote. It does not work:
jQuery(function ($) { var calculate = function () { var total = 0; // Check the selected options of a multi select menu var val1 = $(‘.quform-field-2_34’).val(); if (val1) { if ($.inArray(‘opt1’, val1) = 1) { total += 15; } if ($.inArray(‘opt2’, val1) = 1) { total += 30; } } if ($.inArray(‘opt2’, val1) = 3) { total += 45; } if ($.inArray(‘opt2’, val1) = 4) { total += 55; } }
// Display the result to the user $(‘#form-total’).text(‘Total: $’ + total);
// Set the value of the hidden field $(‘.quform-field-2_38’).val(‘$’ + total); };
// Calculate on page load calculate();
// Recalculate when these select menus are changed $(‘.quform-field-2_34’).change(calculate);