Automatically Calculating a Field Value in Add/Edit Using Va

Talk about any other operations you need to implement: additions, updates etc.

Moderators: ne_moj, zewa, vadimako, ne_moj, zewa, vadimako

johnm
Newbie
Newbie
Posts: 3
Joined: Jul 7th, '14, 04:16

Automatically Calculating a Field Value in Add/Edit Using Va

Postby johnm » Jul 7th, '14, 04:20

I have the purchased the latest Pro version of Datagrid. How do I get Datagrid to automatically calculate my SalesTaxAmount field after I type the value of SalesAmount in ADD/EDIT mode? Both of these fields are in the Sales table referred to in ADD/EDIT mode. However the SalesTaxAmount is calculated based on the Rates field in another TaxRates table.

Regards, John

administrator
Site Admin
Site Admin
Posts: 5988
Joined: Jan 7th, '09, 23:18
Contact:

Re: Automatically Calculating a Field Value in Add/Edit Using Va

Postby administrator » Jul 7th, '14, 05:37

Using this strategy you may also change value of some fields, dependent on other fields.
http://www.apphp.net/forum/viewtopic.php?f=33&t=1955

johnm
Newbie
Newbie
Posts: 3
Joined: Jul 7th, '14, 04:16

Re: Automatically Calculating a Field Value in Add/Edit Using Va

Postby johnm » Jul 8th, '14, 21:13

As far as I can see, that example uses data from within the SAME table. As I said above, what I want to do in ADD mode in the Sales table is to use data from my OTHER TaxRates table. Specifically, for example:
Sales => user enters say $2,000
Tax => a CALCULATED number APPEARS, say $200. The calculation would be 10% * whatever value is typed into the Sales box. The 10% value in the calculation comes from the TaxRates table which is NOT OPEN in Add mode.
Total Sales => a calculated number (Sales + Tax)

Q1 What could be the code in datagrid to get the two (2) calculations to appear as soon as the $2,000 is entered, and
Q2 How would I code the calculations, to access the 10% (say) from the TaxRates table.

I would be very grateful for any help you could give me.

Regards, John

administrator
Site Admin
Site Admin
Posts: 5988
Joined: Jan 7th, '09, 23:18
Contact:

Re: Automatically Calculating a Field Value in Add/Edit Using Va

Postby administrator » Jul 9th, '14, 06:03

All calculation, that must be done in Add/Edit modes are very simple:
1. You check via HTML source the names and IDs of all related fields.
2. you write the JS function that is called on some event, like onchange or onclick and make all calculations in this function, placing result in the target filed.
3. You click on Update button to save the result.


Return to “Additional operations implementation”