Home › Forums › Quform WordPress › Populate select menu from radio buttons if value = 'Yes' › Reply To: Populate select menu from radio buttons if value = 'Yes'
I really appreciate the help from this forum; it was invaluable. In the long run through I ended up finishing this project with a little help from Aldo whom I contracted through codementor.io. He was awesome!
Here is the code I ended up with in case it may help someone else in the future.
In short, it is a collection of radio elements that correspond to a calculated dollar amount (activities to register for) and the selected radio elements dynamically fill 4 select menus that correspond to negative dollar amounts (comped/free activities for logged in users that are of a particular ‘level’). The grand total is then either pushed to PayPal or, if it is $0 then it just says that the user has been registered.
//
//CALCULATE COST OF SELECTED ACTIVITIES
//
jQuery(function ($) {
var calculate = function () {
var total = 0;
var regtext = (val1 + val2 + val3 + val4 + val5 + val6 + val7 + val8 + val9 + val10 + val11 + val12 + val13 + val14 + val15 + val16 + val17 + val18 + val19 + val20)
//ATTENDEE ACTIVITIES
// Attendee Sailing & Snorkeling
var val1 = $('.quform-field-4_32:checked').val();
if (val1 == 'CATAMARAN SAILING AND SNORKELING ADVENTURE ') {
total += 175;
}
// Attendee ATV Tour
var val2 = $('.quform-field-4_33:checked').val();
if (val2 == 'GUIDED ATV TOUR ') {
total += 180;
}
// Attendee Underwater Scooter
var val3 = $('.quform-field-4_34:checked').val();
if (val3 == 'Half-Day Sub Bahamas Underwater Scooter Diving ') {
total += 215;
}
// Attendee Shopping Tour
var val4 = $('.quform-field-4_35:checked').val();
if (val4 == 'PARADISE ISLAND CITY SHOPPING TOUR ') {
total += 135;
}
// Attendee Golf at Baha Mar
var val5 = $('.quform-field-4_36:checked').val();
if (val5 == 'GOLF AT BAHA MAR ') {
total += 215;
}
// Attendee Dolphin Encounter
var val6 = $('.quform-field-4_40:checked').val();
if (val6 == 'BLUE LAGOON ISLAND WITH DOLPHIN “ENCOUNTER” ') {
total += 150;
}
// Attendee Dolphin Swim +100
var val7 = $('.quform-field-4_41:checked').val();
if (val7 == 'DOLPHIN “SWIM” PROGRAM ') {
total += 400;
}
// Attendee Powerboat Excursion + 135
var val8 = $('.quform-field-4_42:checked').val();
if (val8 == 'FULL DAY IN EXUMA POWERBOAT EXCURSION ') {
total += 470;
}
// Attendee Resort Credit
var val9 = $('.quform-field-4_43:checked').val();
if (val9 == 'RESORT CREDIT ') {
total += 150;
}
// Attendee Fishing Trip
var val19 = $('.quform-field-4_69:checked').val();
if (val19 == 'Half-Day Fishing Trip ') {
total += 185;
}
//GUEST ACTIVITIES
// Guest Sailing & Snorkeling
var val10 = $('.quform-field-4_46:checked').val();
if (val10 == 'CATAMARAN SAILING AND SNORKELING ADVENTURE ') {
total += 175;
}
// Guest ATV Tour
var val11 = $('.quform-field-4_47:checked').val();
if (val11 == 'GUIDED ATV TOUR ') {
total += 180;
}
// Guest Underwater Scooter
var val12 = $('.quform-field-4_48:checked').val();
if (val12 == 'Half-Day Sub Bahamas Underwater Scooter Diving ') {
total += 215;
}
// Guest Shopping Tour
var val13 = $('.quform-field-4_49:checked').val();
if (val13 == 'PARADISE ISLAND CITY SHOPPING TOUR ') {
total += 135;
}
// Guest Golf at Baha Mar
var val14 = $('.quform-field-4_50:checked').val();
if (val14 == 'GOLF AT BAHA MAR ') {
total += 215;
}
// Guest Dolphin Encounter
var val15 = $('.quform-field-4_53:checked').val();
if (val15 == 'BLUE LAGOON ISLAND WITH DOLPHIN “ENCOUNTER” ') {
total += 150;
}
// Guest Dolphin Swim + 100
var val16 = $('.quform-field-4_54:checked').val();
if (val16 == 'DOLPHIN “SWIM” PROGRAM ') {
total += 400;
}
// Guest Powerboat Excursion + 135
var val17 = $('.quform-field-4_55:checked').val();
if (val17 == 'FULL DAY IN EXUMA POWERBOAT EXCURSION ') {
total += 470;
}
// Guest Resort Credit
var val18 = $('.quform-field-4_56:checked').val();
if (val18 == 'RESORT CREDIT ') {
total += 150;
}
// Guest Fishing Trip
var val20 = $('.quform-field-4_70:checked').val();
if (val20 == 'Half-Day Fishing Trip ') {
total += 185;
}
var checkTotal = function (elementString) {
var val21 = $(elementString).val();
if (val21 == 'Snorkeling & Sailing - $175 (attendee)') {
total -= 175;
}else if (val21 == 'ATV Tour - $180 (attendee)') {
total -= 180;
}else if (val21 == 'Underwater Scooter - $215 (attendee)') {
total -= 215;
}else if (val21 == 'Shopping Tour - $135 (attendee)') {
total -= 135;
}else if (val21 == 'Golf at Baha Mar - $215 (attendee)') {
total -= 215;
}else if (val21 == 'Dolphin Encounter - $150 (attendee)') {
total -= 150;
}else if (val21 == 'Dolphin Swim - $300 (attendee)') {
total -= 300;
}else if (val21 == 'Powerboat Excursion - $335 (attendee)') {
total -= 335;
}else if (val21 == 'Fishing Trip - $185 (attendee)') {
total -= 185;
}else if (val21 == 'Resort Credit - $150 (attendee)') {
total -= 150;
}else if (val21 == 'Snorkeling & Sailing - $175 (guest)') {
total -= 175;
}else if (val21 == 'ATV Tour - $180 (guest)') {
total -= 180;
}else if (val21 == 'Underwater Scooter - $215 (guest)') {
total -= 215;
}else if (val21 == 'Shopping Tour - $135 (guest)') {
total -= 135;
}else if (val21 == 'Golf at Baha Mar - $215 (guest)') {
total -= 215;
}else if (val21 == 'Dolphin Encounter - $150 (guest)') {
total -= 150;
}else if (val21 == 'Dolphin Swim - $300 (guest)') {
total -= 300;
}else if (val21 == 'Powerboat Excursion - $335 (guest)') {
total -= 335;
}else if (val21 == 'Fishing Trip - $185 (guest)') {
total -= 185;
}else if (val21 == 'Resort Credit - $150 (guest)') {
total -= 150;
}
}
// Comp 1
checkTotal('.quform-field-4_64');
// Comp 2
checkTotal('.quform-field-4_73');
// Comp 3
checkTotal('.quform-field-4_81');
// Comp 4
checkTotal('.quform-field-4_80');
// Display the result to the user
$('#form-total').text('Total: $' + total);
$('#registered-activities').text(regtext);
// Set the value of the hidden fields
$('.quform-field-4_57').val('$' + total);
$('.quform-field-4_65').val(total);
};
// Calculate on page load
calculate();
// Recalculate when these checkboxes/radio buttons are clicked
$('.quform-field-4_32, .quform-field-4_33, .quform-field-4_34, .quform-field-4_35, .quform-field-4_36, .quform-field-4_40, .quform-field-4_41, .quform-field-4_42, .quform-field-4_43, .quform-field-4_46, .quform-field-4_47, .quform-field-4_48, .quform-field-4_49, .quform-field-4_50, .quform-field-4_53, .quform-field-4_54, .quform-field-4_55, .quform-field-4_56, .quform-field-4_64, .quform-field-4_69, .quform-field-4_70, .quform-field-4_73, .quform-field-4_80, .quform-field-4_81').click(calculate);
// Recalculate when these checkboxes/radio buttons are changed
$('.quform-field-4_32, .quform-field-4_33, .quform-field-4_34, .quform-field-4_35, .quform-field-4_36, .quform-field-4_40, .quform-field-4_41, .quform-field-4_42, .quform-field-4_43, .quform-field-4_46, .quform-field-4_47, .quform-field-4_48, .quform-field-4_49, .quform-field-4_50, .quform-field-4_53, .quform-field-4_54, .quform-field-4_55, .quform-field-4_56, .quform-field-4_64, .quform-field-4_69, .quform-field-4_70, .quform-field-4_73, .quform-field-4_80, .quform-field-4_81').change(calculate);
});
//
//POPULATE COMP 1,2,3,4 SELECT MENU FROM RADIO ELEMENTS
//
jQuery(function ($) {
var calculate = function ($select, $select2, $select3, $select4) {
var valueComp2 = $select2.val();
var valueComp3 = $select3.val();
var valueComp4 = $select4.val();
var value = $select.val(),
options = [new Option('Please select', '0')];
var filterOptions = [new Option('Please select', '0')];
if ($('.quform-field-4_32:checked').val() === 'CATAMARAN SAILING AND SNORKELING ADVENTURE <br>') {
options.push(new Option('Snorkeling & Sailing - $175 (attendee)','Snorkeling & Sailing - $175 (attendee)'));
}
if ($('.quform-field-4_33:checked').val() === 'GUIDED ATV TOUR ') {
options.push(new Option('ATV Tour - $180 (attendee)','ATV Tour - $180 (attendee)'));
}
if ($('.quform-field-4_34:checked').val() === 'Half-Day Sub Bahamas Underwater Scooter Diving ') {
options.push(new Option('Underwater Scooter - $215 (attendee)','Underwater Scooter - $215 (attendee)'));
}
if ($('.quform-field-4_35:checked').val() === 'PARADISE ISLAND CITY SHOPPING TOUR ') {
options.push(new Option('Shopping Tour - $135 (attendee)','Shopping Tour - $135 (attendee)'));
}
if ($('.quform-field-4_36:checked').val() === 'GOLF AT BAHA MAR ') {
options.push(new Option('Golf at Baha Mar - $215 (attendee)','Golf at Baha Mar - $215 (attendee)'));
}
if ($('.quform-field-4_40:checked').val() === 'BLUE LAGOON ISLAND WITH DOLPHIN “ENCOUNTER” ') {
options.push(new Option('Dolphin Encounter - $150 (attendee)','Dolphin Encounter - $150 (attendee)'));
}
if ($('.quform-field-4_41:checked').val() === 'DOLPHIN “SWIM” PROGRAM ') {
options.push(new Option('Dolphin Swim - $300 (attendee)','Dolphin Swim - $300 (attendee)'));
}
if ($('.quform-field-4_42:checked').val() === 'FULL DAY IN EXUMA POWERBOAT EXCURSION ') {
options.push(new Option('Powerboat Excursion - $335 (attendee)','Powerboat Excursion - $335 (attendee)'));
}
if ($('.quform-field-4_69:checked').val() === 'Half-Day Fishing Trip ') {
options.push(new Option('Fishing Trip - $185 (attendee)','Fishing Trip - $185 (attendee)'));
}
if ($('.quform-field-4_43:checked').val() === 'RESORT CREDIT ') {
options.push(new Option('Resort Credit - $150 (attendee)','Resort Credit - $150 (attendee)'));
}
if ($('.quform-field-4_46:checked').val() === 'CATAMARAN SAILING AND SNORKELING ADVENTURE ') {
options.push(new Option('Snorkeling & Sailing - $175 (guest)','Snorkeling & Sailing - $175 (guest)'));
}
if ($('.quform-field-4_47:checked').val() === 'GUIDED ATV TOUR ') {
options.push(new Option('ATV Tour - $180 (guest)','ATV Tour - $180 (guest)'));
}
if ($('.quform-field-4_48:checked').val() === 'Half-Day Sub Bahamas Underwater Scooter Diving ') {
options.push(new Option('Underwater Scooter - $215 (guest)','Underwater Scooter - $215 (guest)'));
}
if ($('.quform-field-4_49:checked').val() === 'PARADISE ISLAND CITY SHOPPING TOUR ') {
options.push(new Option('Shopping Tour - $135 (guest)','Shopping Tour - $135 (guest)'));
}
if ($('.quform-field-4_50:checked').val() === 'GOLF AT BAHA MAR ') {
options.push(new Option('Golf at Baha Mar - $215 (guest)','Golf at Baha Mar - $215 (guest)'));
}
if ($('.quform-field-4_53:checked').val() === 'BLUE LAGOON ISLAND WITH DOLPHIN “ENCOUNTER” ') {
options.push(new Option('Dolphin Encounter - $150 (guest)','Dolphin Encounter - $150 (guest)'));
}
if ($('.quform-field-4_54:checked').val() === 'DOLPHIN “SWIM” PROGRAM ') {
options.push(new Option('Dolphin Swim - $300 (guest)','Dolphin Swim - $300 (guest)'));
}
if ($('.quform-field-4_55:checked').val() === 'FULL DAY IN EXUMA POWERBOAT EXCURSION ') {
options.push(new Option('Powerboat Excursion - $335 (guest)','Powerboat Excursion - $335 (guest)'));
}
if ($('.quform-field-4_70:checked').val() === 'Half-Day Fishing Trip ') {
options.push(new Option('Fishing Trip - $185 (guest)','Fishing Trip - $185 (guest)'));
}
if ($('.quform-field-4_56:checked').val() === 'RESORT CREDIT ') {
options.push(new Option('Resort Credit - $150 (guest)','Resort Credit - $150 (guest)'));
}
if (valueComp2 || valueComp3 || valueComp4) {
options.filter(function(option){
if (option.value !== valueComp2 && option.value !== valueComp3 && option.value !== valueComp4 && option.value !== '0') {
filterOptions.push(option);
}
})
}
// Display result
$select.html(filterOptions).val(value);
if ($select.val() === null) {
$select.prop('selectedIndex', 0);
}
};
// Recalculate when these checkboxes/radio buttons are clicked
$('.quform-field-4_32, .quform-field-4_33, .quform-field-4_34, .quform-field-4_35, .quform-field-4_36, .quform-field-4_40, .quform-field-4_41, .quform-field-4_42, .quform-field-4_43, .quform-field-4_46, .quform-field-4_47, .quform-field-4_48, .quform-field-4_49, .quform-field-4_50, .quform-field-4_53, .quform-field-4_54, .quform-field-4_55, .quform-field-4_56, .quform-field-4_64, .quform-field-4_69, .quform-field-4_70, .quform-field-4_73, .quform-field-4_80, .quform-field-4_81').click(function() {calculate($('.quform-field-4_64'), $('.quform-field-4_73'),$('.quform-field-4_80'),$('.quform-field-4_81'))});
$('.quform-field-4_32, .quform-field-4_33, .quform-field-4_34, .quform-field-4_35, .quform-field-4_36, .quform-field-4_40, .quform-field-4_41, .quform-field-4_42, .quform-field-4_43, .quform-field-4_46, .quform-field-4_47, .quform-field-4_48, .quform-field-4_49, .quform-field-4_50, .quform-field-4_53, .quform-field-4_54, .quform-field-4_55, .quform-field-4_56, .quform-field-4_64, .quform-field-4_69, .quform-field-4_70, .quform-field-4_73, .quform-field-4_80, .quform-field-4_81').click(function() {calculate($('.quform-field-4_73'), $('.quform-field-4_64'),$('.quform-field-4_80'),$('.quform-field-4_81'))});
$('.quform-field-4_32, .quform-field-4_33, .quform-field-4_34, .quform-field-4_35, .quform-field-4_36, .quform-field-4_40, .quform-field-4_41, .quform-field-4_42, .quform-field-4_43, .quform-field-4_46, .quform-field-4_47, .quform-field-4_48, .quform-field-4_49, .quform-field-4_50, .quform-field-4_53, .quform-field-4_54, .quform-field-4_55, .quform-field-4_56, .quform-field-4_64, .quform-field-4_69, .quform-field-4_70, .quform-field-4_73, .quform-field-4_80, .quform-field-4_81').click(function() {calculate($('.quform-field-4_80'), $('.quform-field-4_73'),$('.quform-field-4_64'),$('.quform-field-4_81'))});
$('.quform-field-4_32, .quform-field-4_33, .quform-field-4_34, .quform-field-4_35, .quform-field-4_36, .quform-field-4_40, .quform-field-4_41, .quform-field-4_42, .quform-field-4_43, .quform-field-4_46, .quform-field-4_47, .quform-field-4_48, .quform-field-4_49, .quform-field-4_50, .quform-field-4_53, .quform-field-4_54, .quform-field-4_55, .quform-field-4_56, .quform-field-4_64, .quform-field-4_69, .quform-field-4_70, .quform-field-4_73, .quform-field-4_80, .quform-field-4_81').click(function() {calculate($('.quform-field-4_81'), $('.quform-field-4_73'),$('.quform-field-4_80'),$('.quform-field-4_64'))});
});