Jump to content

Javascript adding in update form


Recommended Posts

I have javascript that is adding two fields and submitting this value to a total field in a table. This works fine.

I then have this submission datapage going to an updata datapage up on clicking the submission button.

This upadate datapage give the user a chance to review his submission and make changes. But the javascript adding the two fields does not update the total field in the table if the user changes the values from the two fields that are to be added.

Caspio says it is because of the way the code is written.

Below is the code I am using.

Anyone have any ideas?

Thanks

function calculate()

{

/* Retrieve the value of the Installation time start and store in a variable 'v_InstallStart' */

var v_InstallStart = parseFloat(document.getElementById("EditRecordInstallation_Time_Start").value);

/* Retrieve the value of the field Installation time finish and store in a variable 'v_InstallFinish' */

var v_InstallFinish = parseFloat(document.getElementById("EditRecordInstallation_Time_Finish").value);

/* Subtract the value Installation finish from Installation start to obtain the value of 'v_InstallTotal' */

var v_InstallTotal= (v_InstallFinish - v_InstallStart);

/* Insert a absolute value of the variable 'v_InstallTotal' into the DataPage field Installation_Time */

document.getElementById("EditRecordInstallation_Time").value = Math.abs(v_InstallTotal);

/* Retrieve the value of the Billable time start and store in a variable 'v_BillStart' */

var v_BillStart = parseFloat(document.getElementById("EditRecordBillable_Time_Start").value);

/* Retrieve the value of the field Billable time finish and store in a variable 'v_BillFinish' */

var v_BillFinish = parseFloat(document.getElementById("EditRecordBillable_Time_Finish").value);

/* Subtract the value Billable finish from Billable start to obtain the value of 'v_BillTotal' */

var v_BillTotal= (v_BillFinish - v_BillStart);

/* Insert a absolute value of the variable 'v_BillTotal' into the DataPage field Billable_Time */

document.getElementById("EditRecordBillable_Time").value = Math.abs(v_BillTotal);

/* Retrieve the value of the Warranty time start and store in a variable 'v_WarrStart' */

var v_WarrStart = parseFloat(document.getElementById("EditRecordWarranty_Time_Start").value);

/* Retrieve the value of the field Warranty time finish and store in a variable 'v_WarrFinish' */

var v_WarrFinish = parseFloat(document.getElementById("EditRecordWarranty_Time_Finish").value);

/* Subtract the value Warranty finish from Warranty start to obtain the value of 'v_WarrTotal' */

var v_WarrTotal= (v_WarrFinish - v_WarrStart);

/* Insert a absolute value of the variable 'v_WarrTotal' into the DataPage field Warranty_Time */

document.getElementById("EditRecordWarranty_Time").value = Math.abs(v_WarrTotal);

/* Retrieve the value of the Courtsey Call time start and store in a variable 'v_CourtStart' */

var v_CourtStart = parseFloat(document.getElementById("EditRecordCoutsey_Call_Time_Start").value);

/* Retrieve the value of the field Courtsey Call time finish and store in a variable 'v_CourtFinish' */

var v_CourtFinish = parseFloat(document.getElementById("EditRecordCoutsey_Call_Time_Finish").value);

/* Subtract the value Courtsey Call finish from Coursey Call start to obtain the value of 'v_CourtTotal' */

var v_CourtTotal= (v_CourtFinish - v_CourtStart);

/* Insert a absolute value of the variable 'v_CourtTotal' into the DataPage field Courtsey_Call_Time */

document.getElementById("EditRecordCourtsey_Call_Time").value = Math.abs(v_CourtTotal);

/* Retrieve the value of the Sales time start and store in a variable 'v_SalesStart' */

var v_SalesStart = parseFloat(document.getElementById("EditRecordSales_Time_Start").value);

/* Retrieve the value of the field Sales time finish and store in a variable 'v_SalesFinish' */

var v_SalesFinish = parseFloat(document.getElementById("EditRecordSales_Time_Finish").value);

/* Subtract the value Sales finish from Sales start to obtain the value of 'v_SalesTotal' */

var v_SalesTotal= (v_SalesFinish - v_SalesStart);

/* Insert an absolute value of the variable 'v_SalesTotal' into the DataPage field Sales_Time */

document.getElementById("EditRecordSales_Time").value = Math.abs(v_SalesTotal);

/* Retrieve the value of the AB time start and store in a variable 'v_ABStart' */

var v_ABStart = parseFloat(document.getElementById("EditRecordAB_Time_Start").value);

/* Retrieve the value of the field AB time finish and store in a variable 'v_ABFinish' */

var v_ABFinish = parseFloat(document.getElementById("EditRecordAB_Time_Finish").value);

/* Subtract the value AB finish from AB start to obtain the value of 'v_ABTotal' */

var v_ABTotal= (v_ABFinish - v_ABStart);

/* Insert a absolute value of the variable 'v_ABTotal' into the DataPage field AB_Time */

document.getElementById("EditRecordAB_Time").value = Math.abs(v_ABTotal);

}

/* On submitting the webform, the function calculate is executed */

document.getElementById("caspioform").onsubmit=calculate;

Link to comment
Share on other sites

Hey Mike,

One quick note which might solve the problem is that the fields you are referencing as "EditRecordFIELDNAME" cannot be Display Only fields. So make sure the form element is not "Display Only" because for a display only field there is no unique id reference.

Best,

Bahar M.

Link to comment
Share on other sites

  • 8 years later...

Just an update: You could use the Calculated Values on this one. Calculated Value form element generates dynamic calculations that automatically update as users interact with your form. Similar to Formula Fields and Calculated Fields, you can construct the calculation using functions, logic, constants, values from other fields and SQL expressions that you can use for your Total: https://howto.caspio.com/datapages/datapage-components/calculated-values/

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...