QuForm AutoSum/Calculations

Home Forums Quform WordPress QuForm AutoSum/Calculations

This topic is: not resolved

This topic contains 3 replies, has 2 voices, and was last updated by  Ally 7 months, 3 weeks ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #23818

    orahchris
    Participant

    Hello,

    I’m attempting to use the Javascript guide here that assists QuForm in autosuming fields. However, it appears not to be working and I’m wondering if this has to do with the most recent update (field values). If you’d be so kind as to look at the following and verify everything looks ok? (Note the use of .keyup as we’re attempting to show the result live on the page without having to hit the submit button).

    <div id="form-total"></div>
    <script>
        jQuery(document).ready(function ($) {
            var calculate = function () {
                var total = 0.00;
     
               // A text input field with numeric value
                var val4 = $('.quform-field-3_26').val();            if (val4.length && $.isNumeric(val4)) {
                    total += parseFloat(val4);
                }
    		   // A text input field with numeric value
                var val4 = $('.quform-field-3_31').val();            if (val4.length && $.isNumeric(val4)) {
                    total += parseFloat(val4);
                }
     
                // Display the result to the user
                $('#form-total').text('Total: $' + total);
     
                // Set the value of the hidden field
                $('input[name=.quform-field-3_47]').val('$' + total);        };
     
            // Calculate on page load
            calculate();
     
            // Recalculate when these text input fields are changed
            $('.quform-field-3_26, .quform-field-3_31').keyup(calculate);
            $('.quform-field-3_26, .quform-field-3_31').blur(calculate);    
    
    });
    </script>
    #23892

    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.

    #23973

    orahchris
    Participant

    Hello,

    Thank You. This works great! A final question, I have two sets of calculations running on the same page (each work just fine thanks to your correction above)

     <div id="form-total"></div>
    <script>
        jQuery(document).ready(function ($) {
            var calculate = function () {
                var total = 0.00;
     
                // A text input field with numeric value
                var val26 = $('.quform-field-3_26').val();
                if (val26 && $.isNumeric(val26)) {
                    total += parseFloat(val26);
                }
    
                // A text input field with numeric value
                var val31 = $('.quform-field-3_31').val();
                if (val31 && $.isNumeric(val31)) {
                    total += parseFloat(val31);
                }
    			
                // A text input field with numeric value
                var val30 = $('.quform-field-3_30').val();
                if (val30 && $.isNumeric(val30)) {
                    total += parseFloat(val30);
                }
    
                // A text input field with numeric value
                var val29 = $('.quform-field-3_29').val();
                if (val29 && $.isNumeric(val29)) {
                    total += parseFloat(val29);
                }
    
                // A text input field with numeric value
                var val28 = $('.quform-field-3_28').val();
                if (val28 && $.isNumeric(val28)) {
                    total += parseFloat(val28);
                }
    
                // A text input field with numeric value
                var val27 = $('.quform-field-3_27').val();
                if (val27 && $.isNumeric(val27)) {
                    total += parseFloat(val27);
                }
    
                // A text input field with numeric value
                var val33 = $('.quform-field-3_33').val();
                if (val33 && $.isNumeric(val33)) {
                    total += parseFloat(val33);
                }	
    
                // A text input field with numeric value
                var val32 = $('.quform-field-3_32').val();
                if (val32 && $.isNumeric(val32)) {
                    total += parseFloat(val32);
                }			
     
                // Display the result to the user
                $('#form-total').text('Total Assets: $' + total);
     
                // Set the value of the hidden field
                $('.quform-field-3_47').val('$' + total);
            };
     
            // Calculate on page load
            calculate();
     
            // Recalculate when these text input fields are changed
            $('.quform-field-3_26, .quform-field-3_31, .quform-field-3_30, .quform-field-3_29, .quform-field-3_28, .quform-field-3_27, .quform-field-3_33, .quform-field-3_32').keyup(calculate);
            $('.quform-field-3_26, .quform-field-3_31, .quform-field-3_30, .quform-field-3_29, .quform-field-3_28, .quform-field-3_27, .quform-field-3_33, .quform-field-3_32').blur(calculate);
    
    });
    </script> 
    <div id="form-total-2"></div>
    <script>
        jQuery(document).ready(function ($) {
            var calculate = function () {
                var total = 0.00;
     
                // A text input field with numeric value
                var val35 = $('.quform-field-3_35').val();
                if (val35 && $.isNumeric(val35)) {
                    total += parseFloat(val35);
                }
    
                // A text input field with numeric value
                var val42 = $('.quform-field-3_42').val();
                if (val42 && $.isNumeric(val42)) {
                    total += parseFloat(val42);
                }
    			
                // A text input field with numeric value
                var val41 = $('.quform-field-3_41').val();
                if (val41 && $.isNumeric(val41)) {
                    total += parseFloat(val41);
                }
    
                // A text input field with numeric value
                var val40 = $('.quform-field-3_40').val();
                if (val40 && $.isNumeric(val40)) {
                    total += parseFloat(val40);
                }
    
                // A text input field with numeric value
                var val39 = $('.quform-field-3_39').val();
                if (val39 && $.isNumeric(val39)) {
                    total += parseFloat(val39);
                }
    
                // A text input field with numeric value
                var val38 = $('.quform-field-3_38').val();
                if (val38 && $.isNumeric(val38)) {
                    total += parseFloat(val38);
                }
    
                // A text input field with numeric value
                var val37 = $('.quform-field-3_37').val();
                if (val37 && $.isNumeric(val37)) {
                    total += parseFloat(val37);
                }		
     
                // Display the result to the user
                $('#form-total-2').text('Total Liabilites: $' + total);
     
                // Set the value of the hidden field
                $('.quform-field-3_49').val('$' + total);
            };
     
            // Calculate on page load
            calculate();
     
            // Recalculate when these text input fields are changed
            $('.quform-field-3_35, .quform-field-3_42, .quform-field-3_41, .quform-field-3_40, .quform-field-3_39, .quform-field-3_38, .quform-field-3_37').keyup(calculate);
            $('.quform-field-3_35, .quform-field-3_42, .quform-field-3_41, .quform-field-3_40, .quform-field-3_39, .quform-field-3_38, .quform-field-3_37').blur(calculate);
    
    });
    </script>

    Each script above spits out two calculations that usually look like this: $20 and $-20

    I’d like to create a third field that combines those two final totals for a “net worth” result.

    I assume I could just create a third script with every quform field, but in case there’s an option that isn’t as redundant I figured I’d check first.

    Thanks

    • This reply was modified 7 months, 4 weeks ago by  orahchris.
    #24026

    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 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.