bmarineau Posted February 8, 2014 Report Share Posted February 8, 2014 I am having trouble with a submission form getting a total amount. I can get the javascript to work if I enter values in standard fields. It works fine if I use custom values in a dropdown. Where the code does not work is when I use a cascading dropdown. The form is an internal billing request form. There is a price field which is based on the product selected in a previous form. When the select the product, the price goes into the cascading dropdown and fills in the form properly. After price is a field for additional charges and following that a field for discount. I have the following javascript in the footer of the submission form. <SCRIPT LANGUAGE="JavaScript"> function summation() { var Cost = document.getElementById("InsertRecordPrice").value; var Additional_Charge = document.getElementById("InsertRecordAdditional").value; var Disc = document.getElementById("InsertRecordDiscount").value; var Total_Invoice = parseFloat(Cost) + parseFloat(Additional_Charge) + parseFloat(Disc); document.getElementById("InsertRecordTotal").value = Total_Invoice; } document.getElementById("caspioform").onsubmit=summation; </SCRIPT> There's obviously something I'm not getting about the difference between entering a value and using a cascading dropdown. Technically, it doesn't even need to be a cascading dropdown if there is another way to get a default value from a table. If anyone can see where my error is, please let me know. I even created a stand alone form with only the 5 necessary fields just for experimentation and I'm stumped. Thanks in advance. Quote Link to comment Share on other sites More sharing options...
Jan Posted February 11, 2014 Report Share Posted February 11, 2014 Hello, Bill! As far as I know, when a user sets a field as a parent of a Cascading DropDown, the ID of this parent field becomes dynamic. So, if you add a code like this var elems = document.getElementsByTagName("*"); for (var i=0, m=elems.length; i<m; i++) { if (elems[i].id && elems[i].id.indexOf("InsertRecordPrice") != -1) { var Cost = elems[i].value; } } instead var Cost = document.getElementById("InsertRecordPrice").value; Total price should be calculated. Quote Link to comment Share on other sites More sharing options...
bmarineau Posted February 12, 2014 Author Report Share Posted February 12, 2014 Hello, Bill! As far as I know, when a user sets a field as a parent of a Cascading DropDown, the ID of this parent field becomes dynamic. So, if you add a code like this var elems = document.getElementsByTagName("*"); for (var i=0, m=elems.length; i<m; i++) { if (elems[i].id && elems[i].id.indexOf("InsertRecordPrice") != -1) { var Cost = elems[i].value; } } instead var Cost = document.getElementById("InsertRecordPrice").value; Total price should be calculated. Jan, thank you so much! Your answer worked perfectly. I've been stumped by this one for a while now. 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.