Populate select menu from radio buttons if value = 'Yes'

Home Forums Quform WordPress Populate select menu from radio buttons if value = 'Yes'

This topic is: resolved
  • This topic has 12 replies, 3 voices, and was last updated 5 years ago by Ally.
Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #28985
    masonicdisorder
    Participant

    Hello!

    I have been trying to populate the content of a select menu based on if a radio element = ‘Yes’

    Actually, I have 18 radio elements and need the select menu to populate if/when Yes is selected and set the text AND value of the select menu.

    Each of the Yes/No radio buttons has a dollar amount associated with it; e.g. Radio1($10), Radio2($20), Radio3($30), etc… and the calculation guide made it possible for me to generate a running total and I am passing this over to PayPal through the submit button.

    The purpose of the select menu is to allow the user to choose of of their selected items to get for free. I plan to include the value of the select menu (which will be a negative amount) in the calculation function once it is working.

    I’ve been working with code based on these guides:

    Populating a select menu based on the value of another select menu

    Calculations

    Excellent guides by the way.

    Here is what I have but to be honest I am stuck and literally losing sleep over this because the project is overdue… help?!

    //this works on.click to populate dropdown from radio but only for Yes value
    jQuery(function ($) {
        var $select1 = $('.quform-field-12_5'),
            $select2 = $('.quform-field-12_4');
        
        var data = {
            'Yes': ['Snorkeling & Sailing - $175'],
            'No': ['']
        };
     
        $select1.on('click', function () {
            var value = $select1.val(),
                options = [new Option('Please select', '')];
     
            if (data[value]) {
                for(var i = 0; i < data[value].length; i++) {
                    options.push(new Option(data[value][i], data[value][i]));
                }
            }
     
            $select2.html(options).prop('selectedIndex', 0);
        }).change();
    });

    …then there is this adaptation of the code from the calculate guide that I tested by sending to a textarea element; it works but not to a select menu…

    jQuery(function ($) {
        var calculate = function () {
            var total = [];
    
            // Radio 1
            var val1 = $('.quform-field-12_5:checked').val();
            if (val1 == 'Yes') {
                total += ['Snorkeling & Sailing - $175'];
            } else if (val1 == 'No') {
                total += [];
            }
    
            // Radio 2
            var val2 = $('.quform-field-12_7:checked').val();
            if (val2 == 'Yes') {
                total += ['ATV Tour - $180'];
            } else if (val2 == 'No') {
                total += [];
            }
    
            //Display result
            $('.quform-field-12_6').text(total);
    
        };
    
        // Calculate on page load
        calculate();
    
        // Recalc when changed
        $('.quform-field-12_5, .quform-field-12_7').click(calculate);
    
    });
    #28989
    Goran
    Participant

    HI, I had similar problem so maybe I can help

    can you provide link to your form?

    #29001
    masonicdisorder
    Participant

    The site I am working on is password protected but I’ve exported the form and put it on a site that I am using for testing.

    You can access it here:

    sandbox

    The form id has changed so the code that I have working on the new form is different, but I will change it and get it loaded into this site right now.

    #29006
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #29018
    masonicdisorder
    Participant

    ALLY!

    You freaking rock! Thank you so much… I’ll have this working in no time now (and actually get a normal amount of sleep tonight).

    I’m not sure what’s going on with the sandbox I linked but the real site doesn’t have the errors it does.

    ~ Awesome support and awesome product. Tytyty ~

    #29019
    masonicdisorder
    Participant

    Something is wrong with my code but I can’t seem to find it…. and I have one follow-up question.

    First, here is the expanded version of what you provided. No matter if I add just one more if for a radio button or all of them, only the first two are working. Any additional if I add appear in the select menu no matter the radio button selection.

    Second, I assume that I could add a single line to the existing cost calculation to include the negative value associated with what is chosen from the select menu but despite what I have tried I get NaN or nothing but an error in the console. Here is what I have at the moment.

    The actual site is HERE ~ the password of Nassau

    //CALCULATE SELECTED ACTIVITY COST
    jQuery(function ($) {
        var calculate = function () {
            var total = 0;
    
        //ATTENDEE ACTIVITIES
            // Attendee Sailing & Snorkeling
            var val1 = $('.quform-field-4_32:checked').val();
            if (val1 == 'Yes') {
                total += 175;
            } else if (val1 == 'No') {
                total += 0;
            }
            // Attendee ATV Tour
            var val2 = $('.quform-field-4_33:checked').val();
            if (val2 == 'Yes') {
                total += 180;
            } else if (val2 == 'No') {
                total += 0;
            }
            // Attendee Underwater Scooter
            var val3 = $('.quform-field-4_34:checked').val();
            if (val3 == 'Yes') {
                total += 215;
            } else if (val3 == 'No') {
                total += 0;
            }
            // Attendee Shopping Tour
            var val4 = $('.quform-field-4_35:checked').val();
            if (val4 == 'Yes') {
                total += 135;
            } else if (val4 == 'No') {
                total += 0;
            }
            // Attendee Golf at Baha Mar
            var val5 = $('.quform-field-4_36:checked').val();
            if (val5 == 'Yes') {
                total += 215;
            } else if (val5 == 'No') {
                total += 0;
            }
            // Attendee Dolphin Encounter
            var val6 = $('.quform-field-4_40:checked').val();
            if (val6 == 'Yes') {
                total += 150;
            } else if (val6 == 'No') {
                total += 0;
            }
            // Attendee Dolphin Swim +100
            var val7 = $('.quform-field-4_41:checked').val();
            if (val7 == 'Yes') {
                total += 400;
            } else if (val7 == 'No') {
                total += 0;
            }
            // Attendee Powerboat Excursion + 135
            var val8 = $('.quform-field-4_42:checked').val();
            if (val8 == 'Yes') {
                total += 470;
            } else if (val8 == 'No') {
                total += 0;
            }
            // Attendee Resort Credit
            var val9 = $('.quform-field-4_43:checked').val();
            if (val9 == 'Yes') {
                total += 150;
            } else if (val9 == 'No') {
                total += 0;
            }
            // Attendee Fishing Trip
            var val19 = $('.quform-field-4_69:checked').val();
            if (val19 == 'Yes') {
                total += 185;
            } else if (val19 == 'No') {
                total += 0;
            }
            
    
        //GUEST ACTIVITIES
            // Guest Sailing & Snorkeling
            var val10 = $('.quform-field-4_46:checked').val();
            if (val10 == 'Yes') {
                total += 175;
            } else if (val10 == 'No') {
                total += 0;
            }
            // Guest ATV Tour
            var val11 = $('.quform-field-4_47:checked').val();
            if (val11 == 'Yes') {
                total += 180;
            } else if (val11 == 'No') {
                total += 0;
            }
            // Guest Underwater Scooter
            var val12 = $('.quform-field-4_48:checked').val();
            if (val12 == 'Yes') {
                total += 215;
            } else if (val12 == 'No') {
                total += 0;
            }
            // Guest Shopping Tour
            var val13 = $('.quform-field-4_49:checked').val();
            if (val13 == 'Yes') {
                total += 135;
            } else if (val13 == 'No') {
                total += 0;
            }
            // Guest Golf at Baha Mar
            var val14 = $('.quform-field-4_50:checked').val();
            if (val14 == 'Yes') {
                total += 215;
            } else if (val14 == 'No') {
                total += 0;
            }
            // Guest Dolphin Encounter
            var val15 = $('.quform-field-4_53:checked').val();
            if (val15 == 'Yes') {
                total += 150;
            } else if (val15 == 'No') {
                total += 0;
            }
            // Guest Dolphin Swim + 100
            var val16 = $('.quform-field-4_54:checked').val();
            if (val16 == 'Yes') {
                total += 300;
            } else if (val16 == 'No') {
                total += 0;
            }
            // Guest Powerboat Excursion + 135
            var val17 = $('.quform-field-4_55:checked').val();
            if (val17 == 'Yes') {
                total += 335;
            } else if (val17 == 'No') {
                total += 0;
            }
            // Guest Resort Credit
            var val18 = $('.quform-field-4_56:checked').val();
            if (val18 == 'Yes') {
                total += 150;
            } else if (val18 == 'No') {
                total += 0;
            }
            // Guest Fishing Trip
            var val20 = $('.quform-field-4_70:checked').val();
            if (val20 == 'Yes') {
                total += 185;
            } else if (val20 == 'No') {
                total += 0;
            }
            // Comp 1
            var val21 = $('.quform-field-4_64').val();
            if (val21 == 'Please select') {
                total += 0;
            } else if (val21 == 'Snorkeling & Sailing - $175') {
                total += -175;
            }else if (val21 == 'ATV Tour - $180') {
                total += -180;
            }else if (val21 == 'Underwater Scooter - $215') {
                total += -215;
            }else if (val21 == 'Shopping Tour - $135') {
                total += -135;
            }else if (val21 == 'Golf at Baha Mar - $215') {
                total += -215;
            }else if (val21 == 'Dolphin Encounter - $150') {
                total += -150;
            }else if (val21 == 'Dolphin Swim - $300') {
                total += -300;
            }else if (val21 == 'Powerboat Excursion - $335') {
                total += -335;
            }else if (val21 == 'Resort Credit - $150') {
                total += -150;
            }else if (val21 == 'Fishing Trip - $185') {
                total += -185;
            }
    
            // Display the result to the user
            $('#form-total').text('Total: $' + total);
     
            // Set the value of the hidden field
            $('.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').click(calculate);
    
    });
    
    //Populate Select Menu from Radio Elements
    jQuery(function ($) {
        var $select = $('.quform-field-4_64');
    
        var calculate = function () {
            var value = $select.val(),
                options = [new Option('Please select', '0')];
    
            if ($('.quform-field-4_32').val() === 'Yes') {
                options.push(new Option('Snorkeling & Sailing - $175','-175'));
            }
    
            if ($('.quform-field-4_33').val() === 'Yes') {
                options.push(new Option('ATV Tour - $180','-180'));
            }
    
            if ($('.quform-field-4_34').val() === 'Yes') {
                options.push(new Option('Underwater Scooter - $215','-215'));
            }
    
            if ($('.quform-field-4_35').val() === 'Yes') {
                options.push(new Option('Shopping Tour - $135','-135'));
            }
    
            if ($('.quform-field-4_36').val() === 'Yes') {
                options.push(new Option('Golf at Baha Mar - $215','-215'));
            }
    
            if ($('.quform-field-4_40').val() === 'Yes') {
                options.push(new Option('Dolphin Encounter - $150','-150'));
            }
    
            if ($('.quform-field-4_41').val() === 'Yes') {
                options.push(new Option('Dolphin Swim - $300','-300'));
            }
    
            if ($('.quform-field-4_42').val() === 'Yes') {
                options.push(new Option('Powerboat Excursion - $335','-335'));
            }
    
            if ($('.quform-field-4_43').val() === 'Yes') {
                options.push(new Option('Resort Credit - $150','-150'));
            }
    
            if ($('.quform-field-4_46').val() === 'Yes') {
                options.push(new Option('Snorkeling & Sailing - $175','-175'));
            }
    
            if ($('.quform-field-4_47').val() === 'Yes') {
                options.push(new Option('ATV Tour - $180','-180'));
            }
    
            if ($('.quform-field-4_48').val() === 'Yes') {
                options.push(new Option('Underwater Scooter - $215','-215'));
            }
    
            if ($('.quform-field-4_49').val() === 'Yes') {
                options.push(new Option('Shopping Tour - $135','-135'));
            }
    
            if ($('.quform-field-4_50').val() === 'Yes') {
                options.push(new Option('Golf at Baha Mar - $215','-215'));
            }
    
            if ($('.quform-field-4_53').val() === 'Yes') {
                options.push(new Option('Dolphin Encounter - $150','-150'));
            }
    
            if ($('.quform-field-4_54').val() === 'Yes') {
                options.push(new Option('Dolphin Swim - $300','-300'));
            }
    
            if ($('.quform-field-4_55').val() === 'Yes') {
                options.push(new Option('Powerboat Excursion - $335','-335'));
            }
    
            if ($('.quform-field-4_56').val() === 'Yes') {
                options.push(new Option('Resort Credit - $150','-150'));
            }
    
            if ($('.quform-field-4_69').val() === 'Yes') {
                options.push(new Option('Fishing Trip - $185','-185'));
            }
    
            if ($('.quform-field-4_70').val() === 'Yes') {
                options.push(new Option('Fishing Trip - $185','-185'));
            }
    
            // Display result
            $select.html(options).val(value);
    
            //Place value in hidden control for deduction in cost calculation
            $('.quform-fiels-4_71').val(value);
    
            if ($select.val() === null) {
                $select.prop('selectedIndex', 0);
            }
        };
        
        // Recalculate when these 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_69, .quform-field-4_70').click(calculate);
    });
    #29020
    masonicdisorder
    Participant

    …Dang!
    I really AM tired… I neglected to add “:checked'” at the end of each of the radio fields….

    That part is working now. woo-hoo!

    …this part of the cost calculation still isn’t working as expected though (I tried it with += -150 and -= 150 but neither is working)

    I’m hoping it is something super simple and I’ll figure it out before you get a chance to reply but I wanted to put this “out there” in case it might help anyone else.

    Oh, and the form is here: http://register-here.com/twiy-2019/test/ ~ site pw Nassau

    Thank you!

            // Comp 1
            var val21 = $('.quform-field-4_64').val();
            if (val21 == 'Please select') {
                total += 0;
            } else if (val21 == 'Snorkeling & Sailing - $175') {
                total -= 175;
            }else if (val21 == 'ATV Tour - $180') {
                total -= 180;
            }else if (val21 == 'Underwater Scooter - $215') {
                total -= 215;
            }else if (val21 == 'Shopping Tour - $135') {
                total -= 135;
            }else if (val21 == 'Golf at Baha Mar - $215') {
                total -= 215;
            }else if (val21 == 'Dolphin Encounter - $150') {
                total -= 150;
            }else if (val21 == 'Dolphin Swim - $300') {
                total -= 300;
            }else if (val21 == 'Powerboat Excursion - $335') {
                total -= 335;
            }else if (val21 == 'Resort Credit - $150') {
                total -= 150;
            }else if (val21 == 'Fishing Trip - $185') {
                total -= 185;
            }
    #29021
    masonicdisorder
    Participant

    …Figured it out… I have different values than I have text; e.g., Sailing & Snorkeling – $175 with a VALUE of -175…

    So, I changed the section of the calculation to:

    ` // Comp 1
    var val21 = $(‘.quform-field-4_64’).val();
    if (val21 == ‘-175’) {
    total -= 175;
    }else if (val21 == ‘-180’) {
    total -= 180;
    }else if (val21 == ‘-215’) {
    total -= 215;
    }else if (val21 == ‘-135’) {
    total -= 135;
    }else if (val21 == ‘-215’) {
    total -= 215;
    }else if (val21 == ‘-150’) {
    total -= 150;
    }else if (val21 == ‘-300’) {
    total -= 300;
    }else if (val21 == ‘-335’) {
    total -= 335;
    }else if (val21 == ‘-150’) {
    total -= 150;
    }else if (val21 == ‘-185′) {
    total -= 185;
    }’

    …and it works!

    This post is turning into my dev journal LOL…

    #29022
    masonicdisorder
    Participant

    Now, I just need to copy all of the contents of the dynamically populated select menu except what is selected to another select menu and calculate that one in the same way for users that have 2 comps rather than just 1…

    I’ll post that as soon as I figure that out and then post the whole code for posterity’s sake.

    #29023
    masonicdisorder
    Participant

    I am hoping this is the last little piece of this puzzle I need help with.

    I am really thankful for this forum and the expert assistance.

    In order to see this last part in action you will need to log in not only to the site but as a user because some fields are hidden based on the ‘level’ associated with the user.

    http://register-here.com/twiy-2019/test/
    site pw Nassau

    Log in using the LogIn button on that page
    user exectest
    pw $(ExecTest123!@#)

    Once you’re logged in select a couple of activities to populate the ‘comp’ select menus at the bottom. If there was just one select menu this would project would already be completed but with the two select menus decreasing the calculated cost of the activities it is easily possible to generate an incorrect dollar amount or even negative.

    I tried to remove an option from one of the select menus with this but it did not work:

    //
    //REMOVE SELECTION FROM COMP 2 WHEN SELECTED IN COMP 1
    //
    jQuery(function ($) {
        var comp1 = $('.quform-field-4_64').val();
        $('.quform-field-4_73 option[value=comp1]').remove();
    
    });

    …and things are kind of refreshing weird

    If you can point me in the right direction on this final step I would be ecstatic

    #29043
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #29067
    masonicdisorder
    Participant

    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'))});
    
    });
    
    
    #29075
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

Viewing 13 posts - 1 through 13 (of 13 total)
  • You must be logged in to reply to this topic.
Be inspired. © 2024 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy