This topic is locked
[SOLVED]

 Calculating with multiple fields and Autofill but previous value is used

3/28/2020 7:20:51 AM
PHPRunner General questions
need2sleep authorDevClub member

Came across this interesting scenario on a sales oriented database.
Let's say I have 4 fields:



SalesRep|Profit|ComissionRate|ComissionAmount


I'm trying to do a simple calculation to figure out the Commission Amount based on who sold it since each Sales Rep has their own ComissionRate.
I select 'SalesRep' from a Dropdown and have it Autofill the 'CommissionRate' for that specific rep which is a percentage.
Based on the information from the manual: https://xlinesoft.com/phprunner/docs/how_to_calculate_values_on_the_fly.htm
I use JavaScript OnLoad event to do a calculation with KeyUp/MouseUp event:

'ComissionAmount' = 'Profit' x 'ComissionRate'


But the issue here is that the KeyUp event triggers the calculation before the AutoFill has a chance to input the new rate. So in reality the commission is being calculated but with the previous value in the 'ComissionRate' field instead of the new one that the AutoFill inserts.
Is there a way to trigger the calculation based on a field's value changing?
I know I can use before record update to calculate and store it in the DB correctly but what if we want to see the correct value calculated on the fly before we save the record?
Thank you

Sergey Kornilov admin 3/29/2020

Yes, you can implement the field event tied to CommissionRate field event 'editing' or 'change'. It will not trigger until the value of CommissionRate changes.

need2sleep authorDevClub member 4/3/2020



Yes, you can implement the field event tied to CommissionRate field event 'editing' or 'change'. It will not trigger until the value of CommissionRate changes.


Thank you that did the trick!