How to calculate values on the fly (PHPRunner)

Let’s say there are three fields on the add/edit page: Price, Quantity and Total. To calculate total value on the fly use Javascript code (add it at the end of the page on the Visual Editor tab in HTML mode).

Here is a sample code for PHPRunner 5.1:

<script>
document.forms.editform.value_Price.onchange = document.forms.editform.value_Quantity.onchange = function()
{
document.forms.editform.value_Total.value = document.forms.editform.value_Price.value*document.forms.editform.value_Quantity.value;
}
</script>

and for PHPRunner 5.2. Add this code to ‘Javascript onload’ event of the page where you need this calculation to happen:

var ctrlPrice = Runner.getControl(pageid, 'Price');
var ctrlQuantity = Runner.getControl(pageid, 'Quantity');
var ctrlTotal = Runner.getControl(pageid, 'Total');

function func() {
ctrlTotal.setValue(parseFloat(ctrlPrice.getValue()) * parseFloat(ctrlQuantity.getValue()));
}; 

ctrlPrice.on('keyup', func);
ctrlQuantity.on('keyup', func);

http://www.asprunner.com/forums/topic/13678-how-to-calculate-values-on-the-fly/
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s