senicholas Posted May 8, 2015 Report Share Posted May 8, 2015 I have been working the code below, adding 3 text fields and tying to write the total to the field TTL_Crates, but, I cannot get it to work. Any ideas? <br /> <script language="JavaScript"> function calculate() { var v_one= parseFloat (document.getElementById("InsertRecordCrate_One_Quantity").value); var v_two= parseFloat (document.getElementById("InsertRecordCrate_Two_Quantity").value); var v_three= parseFloat (document.getElementById("InsertRecordCrate_Three_Quantity").value); var v_total = (v_one + v_two + v_three); document.getElementByID(“InsertRecordTTL_Cratesâ€).value= (v_total); } /* On submitting the webform, the function calculate is executed */ document.getElementById("InsertRecordBid_Order Web Form_1").onsubmit=calculate; Quote Link to comment Share on other sites More sharing options...
Jan Posted May 18, 2015 Report Share Posted May 18, 2015 Hello senicholas, You can try using the following script: <script language="JavaScript"> function calculate() { var v_one = parseFloat(document.getElementById("InsertRecordCrate_One_Quantity").value); var v_two = parseFloat(document.getElementById("InsertRecordCrate_Two_Quantity").value); var v_three = parseFloat(document.getElementById("InsertRecordCrate_Three_Quantity").value); var v_total = v_one + v_two + v_three; document.getElementByID(“InsertRecordTTL_Cratesâ€).value = v_total; } /* On submitting the webform, the function calculate is executed */ document.getElementById("caspioform").onsubmit=calculate; </script> I hope, it helps. Quote Link to comment Share on other sites More sharing options...
senicholas Posted May 23, 2015 Author Report Share Posted May 23, 2015 Thanks, I made the modifications, but it still does not write to the DB. Are only text fields allowed to writer to? Quote Link to comment Share on other sites More sharing options...
Jan Posted May 25, 2015 Report Share Posted May 25, 2015 Hello senicholas, As far as i know, usually "Hidden" and "Text Area" fields are allowed too. There are some tricks with Dropdowns and Listboxes, Checkboxes and Radiobuttons. Which Form Element do you use? Could you provide the URL of your page? Quote Link to comment Share on other sites More sharing options...
senicholas Posted May 25, 2015 Author Report Share Posted May 25, 2015 The crate_one_Quanity fields are number fields and the ttl_crate field is a text. The url on my test page is: https://b5.caspio.com/dp.asp?AppKey=9f653000b65254d3e607447ab34e Quote Link to comment Share on other sites More sharing options...
senicholas Posted May 25, 2015 Author Report Share Posted May 25, 2015 Maybe this is my problem, I have the crate_xx_quanity fields in the form as text, but the db is number. Quote Link to comment Share on other sites More sharing options...
Jan Posted May 26, 2015 Report Share Posted May 26, 2015 If I understand correctly, now the following code is used: <script language="JavaScript"> function calculate() { var v_one= parseFloat (document.getElementById("InsertRecordCrate_One_Quantity").value); var v_two= parseFloat (document.getElementById("InsertRecordCrate_Two_Quantity").value); var v_three= parseFloat (document.getElementById("InsertRecordCrate_Three_Quantity").value); var v_total = v_one + v_two + v_three; document.getElementByID(“InsertRecordTTL_Cratesâ€).value= v_total; } document.getElementById("caspioform").onsubmit=calculate; </script> There are two misprints in the following line document.getElementByID(“InsertRecordTTL_Cratesâ€).value= v_total; } Incorrect quotes and "ID" You can try to change the line as follows: document.getElementById("InsertRecordTTL_Crates").value= v_total; } I hope, it helps. Quote Link to comment Share on other sites More sharing options...
senicholas Posted May 27, 2015 Author Report Share Posted May 27, 2015 I changed the default value to 0 on the fields I am adding and it works like a charm. Thank you very much!!!! Quote Link to comment Share on other sites More sharing options...
Kurumi Posted June 10, 2019 Report Share Posted June 10, 2019 Hi @senicholas, As Caspio had their releases. You can now do this without using JavaScript. You can check it 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 total. Check these videos for more information: I hope it 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.