Auto Calculate Values

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
JAW
User
Posts: 98

Auto Calculate Values

Post by JAW »

Hello,
I want to auto calculate two field values to be displayed in another field. The code below works fine on the xxxadd.php page;

<script type="text/javascript"><!--
function updatesum() {
document.finvoiceitemsadd.x_ItemTotal.value = (document.finvoiceitemsadd.x_Quantity.value -0) * (document.finvoiceitemsadd.x_Override.value -0);
}
//--></script>
When I input the values in the fields the total calculates. All is good.

Now I want to use Grid Add in the detail page. The page looks exactly how I want it to look but I cannot get this to work there. I noticed that the field ID's now have a number like x1_Quantity and x2Quantity. How can I dynamically append that number to my code above to replicate across all the row in the Grid Add page? I need to get the Row Number somehow.

Thanks
JW


danielc
User
Posts: 1601

Post by danielc »

  1. Add "this" to your onchange event when you call to the function: "updatesum(this)".
  2. Modify your function to get the element, e.g. function updatesum(elem).
  3. Manipulate the elem.id (x?_yourfield) in your function to get the row index (between x and _).

Post Reply