|
Hi Ann.
Thank you kindly for your help. I had a good play with some of the suggestions over the weekend and here are my thoughts and report:
- I had no luck at all with the Javascript onload code (it didn't do anything and gave errors when trying to edit data) - what is this supposed to do exactly? Does it actually update the database? And I'd be interested to know if there is a working demo of this event somewhere.
- Using the code you gave, the balance didn't update correctly - I beleive the reason for this is that there is no balance in the current row when I add a new entry. Perhaps I didn't explain it clearly enough - my aim is to give a running total (like a bank statement) where every investment is deducted from the previous balance and then the return added to this balance when the investment is sold.
The table should develop something like this (the settled field is simply a 0/1 switch). Let's assume the initial balance is 200): investment|return|settled|balance
(null), (null), 0, 200
100, (null), 0, 100 investment|return|settled|balance
(null), (null), 0, 200
100, 200, 1, 300 investment|return|settled|balance
(null), (null), 0, 200
100, 200, 1, 300
120, (null), 0, 180 investment|return|settled|balance
(null), (null), 0, 200
100, 200, 1, 300
120, 130, 1, 310 I did manage to get this event to work on edit page, before record updated (ie. when I input the return): if (($values["return"]!=NULL) && ($values["settled"] =="0"))
{
$values["balance"] = $oldvalues["balance"]+$values["return"];
$values["settled"] = "1";
}
return true; However, I did not manage to find a way to "pull" the old balance from the previous row when inputting the initial investment. Regards,
Mandy
|