Refreshing a variable on form after calculation

Haven’t been able to find the answer in the manuals, although it is likely in there somewhere.

Scenario:
User enters a number value in variable field 1 (Price)
Tabs to variable field 2 and enters another number (Shipping)
Upon tabbing again, how do I get the form to refresh variable field 3 in order to show the sum of the two fields? (Total Sale)

I think:

In calculation

field3=field1+field2

databaseManager.savedata

Sorry, no sale; it didn’t work. Sounds like an easy thing to do, and it probably is once a person knows the proper command…

These are fields with (form) variables as dataprovider ?
So then you can’t use calculations (as dataprovider) but have to use a method that is triggered on a onDatachange event.
I.e. you make 1 method that calculated the value like JuanMartin already showed and hook it up to the onDatachange event of the 2 other fields on the form.

Hope this helps.

if they are just 2 db columns or other calcs.
Then if you change 1 column in a textfield and you tab out it should already calculate your calc
Dont have to save for that.

This is what finally worked:

onFocustLost at field 2 calls this function:

function calc_totalsale() {
totalsale = merch + shipping;
elements.totalsale.requestFocus();
}

NOW, if I can just get totalsale to display and have the cursor skip straight to the next entry field without stopping there I will be able to move on to the next thing I have to learn with Servoy…