Jump to content

Total Field In A Submission Form


Go to solution Solved by Jan,

Recommended Posts

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.

Link to post
Share on other sites
  • Solution
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.

Link to post
Share on other sites

 

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.

Link to post
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...