PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Updating total when using gform_product_total and other fields

  1. Hello,

    Background Info:
    This is an order form for a text ad listing. There is a commercial rate and non-profit rate. The user can select how many months they wish for their ad to run for. Using product field and quantity field works perfectly to update the total. My issue is in a second option to allow the user to 'upgrade' their listing with an image (checkbox field) should add $25/month to the total.

    Here is my setup:

    Product:
    Commercial - $50
    Non-Profit - $35

    Options:
    1 Month|1
    2 Months|2
    ...
    12 Months|12

    Upgrade?:
    Checkbox (default is unchecked)

    My function to update the total:

    function gform_product_total(formId, total){
            if (jQuery("#choice_22_1").is(":checked")) { //Checks to see if 'upgrade' checkbox is checked or not
            	var monthRun = (jQuery("#input_12_20").val()); //Product options drop down with options for 1-12 months with values of 1-12
    	        var logoCost = (25 * monthRun); //Computes additional cost if checkbox to use logo/image is checked
        	    return total + logoCost; //Computes total of additional cost and base cost of product
        	} else {
        		return total;
        	}
        }

    This function updates the total properly but it won't auto-update the field. I have to go back and click on the radio button for the product type, e.g., commercial before it updates the total.

    How can I force the total to update when the user checks the upgrade box?

    Also if you have any recommendations to make my function cleaner I'm all ears.

    Thanks

    Posted 12 years ago on Wednesday February 29, 2012 | Permalink
  2. So I've continued tinkering around with this and I did figure out that it doesn't matter what order the fields are so I moved the upgrade option above the product so they will more than likely click the upgrade button before the product radio button which solves the issue (sort of). It's still an issue if they go through and select a product and number of months and then go back and click the 'upgrade' checkbox. I would still like to figure out a better solution for this but thought I would update this thread with this information.

    Thanks,
    GB

    Posted 12 years ago on Wednesday February 29, 2012 | Permalink
  3. Continued messing around with this today and solved my issue (although somebody else might have this issue in the future).

    When somebody clicks the 'upgrade' option I set a File Upload field to display using conditional logic below the checkbox which fires the function to update the total.

    While this solves my problem somebody else might want this functionality but not need an additional form element displayed when a box is checked. Maybe an alternative way to update the box would be to create a blank hidden field that displays when a box is checked? I'm not for sure if that will update the total but it might. I did not try this but just thought of it in case somebody stumbles across this.

    Posted 12 years ago on Thursday March 1, 2012 | Permalink