This topic is locked

javascript to calc on the fly

2/22/2011 11:29:52 AM
ASPRunnerPro General questions
T
Tim author

Hello,
I used the example in the help file to calculate values on the fly and edited it for my form. I need to do the following math: ((ProductCost + DeliveryCost) SalesTax) = Total. I have the following code:
var ctrlProductCost = Runner.getControl(pageid, 'ProductCost');

var ctrlDeliveryCost = Runner.getControl(pageid, 'DeliveryCost');

var ctrlSalesTax = Runner.getControl(pageid, 'SalesTax');

var ctrlTotal = Runner.getControl(pageid, 'Total');
function func() {

if ( ctrlProductCost.getValue()!='' && ctrlDeliveryCost.getValue() && ctrlSalesTax.getValue() && !isNaN(ctrlProductCost.getValue()) && !isNaN(ctrlDeliveryCost.getValue()) && !isNaN(ctrlSalesTax.getValue()))
ctrlTotal.setValue((parseFloat(ctrlProductCost.getValue()) + parseFloat(ctrlDeliveryCost.getValue()))
parseFloat(ctrlSalesTax.getValue()));
else

ctrlTotal.setValue('');

};
ctrlProductCost.on('keyup', func);

ctrlDeliveryCost.on('keyup', func);

ctrlSalesTax.on('keyup', func);
This works correctly when I hit save, but it does not update the Total field as the other fields are changed. Do I have something wrong in my code?
Thanks,

Tim

Sergey Kornilov admin 2/22/2011

Your code looks correct.
If you have a valid support contract post your application to Demo Account and open a ticket at http://support.xlinesoft.com sending your Demo Account URL. 'Demo Account' button can be found on the last screen in the program.

T
Tim author 2/22/2011

Hi,
Thanks for the reply, and sorry to waste your time. I figured it out: the Total field was read-only. I'd actually like it to be read-only, but I can see why the update-on-the-fly doesn't work when it is. Any thoughts on how to get it to update AND be read-only?
thanks,

Tim

Sergey Kornilov admin 2/22/2011

Tim,
make it disabled. Javascript API provides setDisabled() function for this purpose.