Jump to content

Calculated Grand Total Field In Submission Form


Recommended Posts

I have a submission form that will capture a transaction total, 5 separate invoice totals, and freight charged.

 

I would like to create a field that would add all the invoice totals and freight to a grand total.

 

Also with a condition that would not allow the form to be submitted if the transaction total and invoice grand total are not equal.

 

Is this possible in a submission form?

Link to comment
Share on other sites

Liz,

 

Are you looking to have this calculation done on submission or on some other type of action before it is submitted?

 

Here is an example that I hope gets you started.  As a note, the invoice_total field will need to be a form element text field and hidden using the method found in http://howto.caspio.com/tech-tips-and-articles/common-customizations/how-to-hide-fields-in-datapages/

 

<SCRIPT LANGUAGE="JavaScript">

 function calculate()
 {
   /* Retrieve the value of the field Transaction_Total and store in a variable 'v_trans' */
   var v_trans = parseFloat(document.getElementById("InsertRecordTransaction_Total").value);

   /* Retrieve the value of the field Invoice1 and store in a variable 'v_invoice1' */
   var v_invoice1 = parseFloat(document.getElementById("InsertRecordInvoice1").value);

   /* Retrieve the value of the field Invoice2 and store in a variable 'v_invoice2' */
   var v_invoice2 = parseFloat(document.getElementById("InsertRecordInvoice2").value);

   /* Retrieve the value of the field Invoice3 and store in a variable 'v_invoice3' */
   var v_invoice3 = parseFloat(document.getElementById("InsertRecordInvoice3").value);

   /* Retrieve the value of the field Invoice4 and store in a variable 'v_invoice4' */
   var v_invoice4 = parseFloat(document.getElementById("InsertRecordInvoice4").value);

   /* Retrieve the value of the field Invoice5 and store in a variable 'v_invoice5' */
   var v_invoice5 = parseFloat(document.getElementById("InsertRecordInvoice5").value);

   /* Retrieve the value of the field Freight_charged and store in a variable 'v_freight' */
   var v_freight = parseFloat(document.getElementById("InsertRecordFreight_charged").value);

   /* Add all invoices and freight charged and store in variable v_invtotal */
   var v_invtotal= v_invoice1 + v_invoice2 + v_invoice3 + v_invoice4 + v_invoice5 + v_freight;
  
   /*Check if v_invtotal = v_trans*/
   if ( v_invtotal == v_trans)
   {
        /* Insert a  value of the variable v_invtotal into the DataPage field Invoice_Total */
        document.getElementById("InsertRecordInvoice_Total").value = v_invtotal;
   }
   else
   {
       
        alert('Transaction Total does not equal values entered. Please re-enter values');
       
   }
 }

 /* On submitting the webform, the function calculate is executed */
 document.getElementById("caspioform").onsubmit=calculate;

</SCRIPT>

Link to comment
Share on other sites

Hi!

 

I was hoping to have the use be able to see the total as the information was entered and then execute the check on submit. But if I am not able to this will work just fine.

 

I did as you instructed and hid the invoice total field. I updated the parameters names to the field names used in my table and inserted into the footer of my data page. When I tested the functionality, whether my totals are equal or not, I receive the pop alert and then when I click ok, the form submits. ?

 

Are you able to assist? Do you need me to send you any information to see?

Link to comment
Share on other sites

Liz, did you make all of the fields, including the invoice_total field required.  The way I have setup the if/else is that if the values of v_invtotal and v_trans are equal the value of v_invtotal is written to invoice_total. If not equal, the message will occur and the value will not be written to the field. Being it is a required field, a blank value will not be allowed.  I'm taking a look at incorporating a button to trigger the calculation and make use of a virtual field to display the temporary total for comparison and will update my post on what I come up with.

Link to comment
Share on other sites

Hi,

 

The ields were not required. I have set them all to required and have set their default value to 0.00 on load so that there will be no blank values if the fields are not required to be used be the end user.

 

However, when I have all value fields populated and balanced the script still delivers the alert message that there was an error and then submitted the form when clicking "ok" to the alert. It also does this when they do not balance.

Edited by Liz
Link to comment
Share on other sites

  • 1 month later...
  • 4 years later...

Hi @lmooring 

As of July 12, 2018, Caspio introduced new features which you can find here: https://howto.caspio.com/release-notes/caspio-bridge-13-0/

This release includes a new feature, Calculated Values in Submission Forms.  This allows you to generate calculations which you can use for your transaction total and grand total.

Check these videos for more information:

 

I hope it helps!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...