Forums

How to Compute product of two varibles

dariegler 10 Mar, 2015
i have two variables quantity and amount. i need to compute the quantity 8 x amount. and where do i put the calculation?
GreyHead 10 Mar, 2015
Hi dariegler,

It depends where you want the calculation to display. If you want an immediate result you'd use JavaScript in a Load JS action in the On Load event of your form.

If you want to calculate only after the form is submitted use PHP In a Custom Code action in the On Submit event of your form.

Note that even if you use JavaScript for an immediate result you should re-check the calculation with PHP after the form is submitted.

Bob
dariegler 10 Mar, 2015
thanks, that is what i thought from reading the faq's. I am not a php coder so what would the code be in custom code? or java script?
dave
GreyHead 10 Mar, 2015
Hi dariegler,

You'll find many examples in the forums here or by Googling around.

If you put the input names and the calculation specification here then we may be able to write some code for you if time allows.

Bob
dariegler 10 Mar, 2015
the names are [amt] and [number] and i want to multipliy them to produce [cost]
GreyHead 10 Mar, 2015
Answer
Hi dariegler,

The PHP version would be
<?php
$form->data['cost'] = $form->data['amt'] * $form->data['number'];
?>

Bob
dariegler 10 Mar, 2015
:D Thank you very much. i struggled with this for 3 days.😉 😉
This topic is locked and no more replies can be posted.