Add sum of combobox values to inputbox …

Home Forums Quform WordPress Add sum of combobox values to inputbox …

This topic is: not resolved
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #5050
    Tekanewa
    Participant

    I have several combo-boxes with conditional logic applied to them in my form and I would like to add the total of the individual combo-box values into another text-box at the bottom of the form. I also need the text-box that shows the total amount to be blocked from editing by the form user so that the calculated sum can not be changed.

    How can I do that?

    Thank you!

    #5057
    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.

    #5060
    Tekanewa
    Participant

    After some tinkering, the following code seems to do what I need, although there might be a better way to program it:

    There are 5 select boxes($day1 – $day5) with conditional logic applied ($logic) and the script is supposed to add only those select boxes that are visible. Also, the input box that is showing the total number will be set to read-only so the user can’t overwrite the calculated value:


    <script type="text/javascript">
    jQuery(function($) {
    $('.iphorm_4_90').attr('readonly', true);
    var $logic = $('.iphorm_4_54');
    var $day1= $('.iphorm_4_49');
    var $day2= $('.iphorm_4_50');
    var $day3= $('.iphorm_4_75');
    var $day4= $('.iphorm_4_76');
    var $day5= $('.iphorm_4_77');
    $logic.change( function(){Add_All_Hours();});
    $day1.change( function(){Add_All_Hours();});
    $day2.change( function(){ Add_All_Hours();});
    $day3.change( function(){Add_All_Hours();});
    $day4.change( function(){Add_All_Hours();});
    $day5.change( function(){Add_All_Hours();});
    function Add_All_Hours() {
    var $days = $('.iphorm_4_54').val();
    var totalHours = 0;
    if ($.isNumeric($day1.val()) && parseFloat($days) > 0) {
    totalHours = totalHours + parseFloat($day1.val());
    }
    if ($.isNumeric($day2.val()) && parseFloat($days) > 1) {
    totalHours = totalHours + parseFloat($day2.val());
    }
    if ($.isNumeric($day3.val()) && parseFloat($days) > 2) {
    totalHours = totalHours + parseFloat($day3.val());
    }
    if ($.isNumeric($day4.val()) && parseFloat($days) > 3) {
    totalHours = totalHours + parseFloat($day4.val());
    }
    if ($.isNumeric($day5.val()) && parseFloat($days) > 4) {
    totalHours = totalHours + parseFloat($day5.val());
    }
    $('.iphorm_4_90').text(totalHours);
    $('.iphorm_4_90').val(totalHours);
    }
    Add_All_Hours();
    });
    </script>

    #5063
    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.

    #5078
    Lifeischoice
    Participant

    Hello Takanewa,

    Thanks for sharing the code….Please where did you put the code above?

    #5089
    tmh2k1
    Participant

    Hi Ally,

    Is there any way to add the sum of single line fields? I just need the user to see the total number of beer cases that hey are ordering.

    Attached is a screen shot of the lines I need a total for. Thank you.

    Attachments:
    You must be logged in to view attached files.
    #5126
    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 7 posts - 1 through 7 (of 7 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