Please enable JavaScript to view this site.

Navigation: Advanced topics > Programming topics > JavaScript API > Examples

How to calculate values on the fly

Scroll Prev Next More

 

Let's say there are three fields on the Add/Edit page: Price, Quantity and Total. To calculate the total value on the fly, use the following JavaScript code (add it to the Add page: JavaScript OnLoad event or Edit page: JavaScript OnLoad event on the Events tab).

 

 

var ctrlPrice = Runner.getControl(pageid, 'Price');
var ctrlQuantity = Runner.getControl(pageid, 'Quantity');
var ctrlTotal = Runner.getControl(pageid, 'Total');
 
function func() {
  ctrlTotal.setValue(Number(ctrlPrice.getValue()) * Number(ctrlQuantity.getValue()));
};
 
ctrlPrice.on('keyup', func);
ctrlQuantity.on('keyup', func);

See also:

JavaScript API: Control object > getControl()

JavaScript API: Control object > setValue()

JavaScript API: Control object > getValue()

JavaScript API: Control object

Field events

JavaScript API