lmooring Posted September 16, 2014 Report Share Posted September 16, 2014 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? nguyencamvnh 1 Quote Link to comment Share on other sites More sharing options...
GoCubbies Posted September 16, 2014 Report Share Posted September 16, 2014 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> lmooring 1 Quote Link to comment Share on other sites More sharing options...
lmooring Posted September 17, 2014 Author Report Share Posted September 17, 2014 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? Quote Link to comment Share on other sites More sharing options...
GoCubbies Posted September 17, 2014 Report Share Posted September 17, 2014 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. Quote Link to comment Share on other sites More sharing options...
lmooring Posted September 18, 2014 Author Report Share Posted September 18, 2014 (edited) 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 September 18, 2014 by Liz Quote Link to comment Share on other sites More sharing options...
GoCubbies Posted September 18, 2014 Report Share Posted September 18, 2014 Liz, Here is an example of my page: http://b5.caspio.com/dp.asp?AppKey=d6673000fce2a2e6b4d64a5a900a Do not have a value set initially for the invoice_total, make sure it is blank. Quote Link to comment Share on other sites More sharing options...
lmooring Posted September 25, 2014 Author Report Share Posted September 25, 2014 I've finally gotten this to work. I had a typo in one of my parameter names and made one of the changes you recommended above. Thanks so much for your help with this! nguyencamvnh 1 Quote Link to comment Share on other sites More sharing options...
pdxweird Posted November 5, 2014 Report Share Posted November 5, 2014 Is there an abbreviated version that is just: "If total = 1, then OK, proceed as normal. If total equals anything other than 1, alert "WARNING MESSAGE"? Thanks so much for any help. Quote Link to comment Share on other sites More sharing options...
Meekeee Posted December 4, 2018 Report Share Posted December 4, 2018 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! Quote Link to comment Share on other sites More sharing options...
Aether Posted December 4, 2018 Report Share Posted December 4, 2018 Hello lmooring, You can also use Totals & Aggregation to use in this process, check this documentation: https://howto.caspio.com/datapages/reports/advanced-reporting/totals-and-aggregations/ I hope this helps ~WatashiwaJin~ Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.