rickin21 Posted August 21, 2017 Report Share Posted August 21, 2017 Hi, I am trying to perform a calculation on one of the field "Amount" - the calculation is pretty much (regular hours x regular rate) + (overtime hours * overtime rate). I have the following javascript below but it does not seem to work. Please help me resolve this issue! Fields: Amount, Regular_Hours, OT_Hours, Rates and Rate_OT <SCRIPT LANGUAGE="JavaScript"> function calculate() { var v_hours = parseFloat(document.getElementById("InsertRecordRegular_Hours").value); var v_hoursot = parseFloat(document.getElementById("InsertRecordOT_Hours").value); var v_rates = parseFloat(document.getElementById("InsertRecordRates").value); var v_ratesot = parseFloat(document.getElementById("InsertRecordRate_OT").value); var v_amount = ((v_hours * v_rates)+(v_hoursot * v_ratesot)); document.getElementById("InsertRecordAmount").value = v_amount; } /* On submitting the webform, the function calculate is executed */ document.getElementById("Regular_Hours").onchange=calculate; document.getElementById("OT_Hours").onchange=calculate; </SCRIPT> Quote Link to comment Share on other sites More sharing options...
Vitalikssssss Posted August 22, 2017 Report Share Posted August 22, 2017 Hi rickin21, You may try to change the triggering event to ".onsubmit". <SCRIPT LANGUAGE="JavaScript"> function calculate() { var v_hours = parseFloat(document.getElementById("InsertRecordRegular_Hours").value); var v_hoursot = parseFloat(document.getElementById("InsertRecordOT_Hours").value); var v_rates = parseFloat(document.getElementById("InsertRecordRates").value); var v_ratesot = parseFloat(document.getElementById("InsertRecordRate_OT").value); var v_amount = ((v_hours * v_rates)+(v_hoursot * v_ratesot)); document.getElementById("InsertRecordAmount").value = v_amount; } /* On submitting the webform, the function calculate is executed */ document.getElementById("caspioform").onsubmit=calculate; </SCRIPT> Hope this helps. Quote Link to comment Share on other sites More sharing options...
Mathilda Posted August 22, 2017 Report Share Posted August 22, 2017 19 hours ago, rickin21 said: Hi, I am trying to perform a calculation on one of the field "Amount" - the calculation is pretty much (regular hours x regular rate) + (overtime hours * overtime rate). I have the following javascript below but it does not seem to work. Please help me resolve this issue! Fields: Amount, Regular_Hours, OT_Hours, Rates and Rate_OT <SCRIPT LANGUAGE="JavaScript"> function calculate() { var v_hours = parseFloat(document.getElementById("InsertRecordRegular_Hours").value); var v_hoursot = parseFloat(document.getElementById("InsertRecordOT_Hours").value); var v_rates = parseFloat(document.getElementById("InsertRecordRates").value); var v_ratesot = parseFloat(document.getElementById("InsertRecordRate_OT").value); var v_amount = ((v_hours * v_rates)+(v_hoursot * v_ratesot)); document.getElementById("InsertRecordAmount").value = v_amount; } /* On submitting the webform, the function calculate is executed */ document.getElementById("Regular_Hours").onchange=calculate; document.getElementById("OT_Hours").onchange=calculate; </SCRIPT> Hi, InsertRecord is missing before field names in the following lines: document.getElementById("Regular_Hours").onchange=calculate; document.getElementById("OT_Hours").onchange=calculate; You may use onblur event in order to run function onchange, also I would recommend adding one more conditions in order to check that all the values which are being used in calculation are fulfilled with data <SCRIPT LANGUAGE="JavaScript"> function calculate() { var v_hours = parseFloat(document.getElementById("InsertRecordRegular_Hours").value); var v_hoursot = parseFloat(document.getElementById("InsertRecordOT_Hours").value); var v_rates = parseFloat(document.getElementById("InsertRecordRates").value); var v_ratesot = parseFloat(document.getElementById("InsertRecordRate_OT").value); if (isNaN(v_hours) || v_hours.length<1) { v_hours = 0; }else if (isNaN(v_hoursot) || v_hoursot.length<1) { v_hoursot = 0; }else if (isNaN(v_rates) || v_rates.length<1) { v_rates = 0; }else if (isNaN(v_ratesot ) || v_ratesot.length<1) { v_ratesot = 0; } var v_amount = ((v_hours * v_rates)+(v_hoursot * v_ratesot)); if ( isNaN(v_amount)){ v_amount = ""; } document.getElementById("InsertRecordAmount").value = v_amount; } document.getElementById("InsertRecordRegular_Hours").onblur=calculate; document.getElementById("InsertRecordOT_Hours").onblur=calculate; </SCRIPT> Cheers! rickin21 1 Quote Link to comment Share on other sites More sharing options...
rickin21 Posted August 22, 2017 Author Report Share Posted August 22, 2017 Hi guys, Thank you for your help! This still does not seem to do anything but I appreciate the effort! Quote Link to comment Share on other sites More sharing options...
Mathilda Posted August 28, 2017 Report Share Posted August 28, 2017 On 8/22/2017 at 10:37 PM, rickin21 said: Hi guys, Thank you for your help! This still does not seem to do anything but I appreciate the effort! Are there any errors in browser's console? You may send me an URL and I will check Quote Link to comment Share on other sites More sharing options...
Kurumi Posted October 29, 2018 Report Share Posted October 29, 2018 Hi @rickin21, 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 Amount. Check these videos for more information: I hope this helps! 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.