Dear Team
i am creating forms & in forms there is some fields required Calculation . is there any idea how to calculate two field value ?
for example
Cost * Qty = Total Value
Best Regards
Mazahir Naya
Dear Team
i am creating forms & in forms there is some fields required Calculation . is there any idea how to calculate two field value ?
for example
Cost * Qty = Total Value
Best Regards
Mazahir Naya
The specific code for performing calculations with field values really depends on the field types you're using, but this page in the online help is a great place to start. Here's the "adding fields together" example from that page, slightly modified to multiply fields.
$(document).ready(function () { $('.sum').on('blur', 'input', sumtotal); function sumtotal() { var s = 1; $('.sum input').each(function () { s *= parseNumber($(this).val()); }); $('.total input').val(s); } function parseNumber(n) { var f = parseFloat(n); //Convert to float number. return isNaN(f) ? 0 : f; //treat invalid input as 0; } });
The code works by adding the "sum" class to each field that will be multiplied, and the "total" class to the field where the total will go. This example will work if there's one set of fields to be multiplied. If you have several sets on your form, you'll need to differentiate them by using additional classes.
i used the above code and i get the wrong answer. ive been testing it and when i put lets say field 1= 2 field 2= 2 total= 16. any ideas?
Did you modify the code at all? How many fields are you multiplying together? Here's a screenshot of the setup mentioned in the example:
How would you change this so it would take the value from a field and multiple it by a value in a dropdown?
Update,
I got the same problem as Armando Ontiveros where the input multiplies itself. That only happens when you use the number or currency input field. It woks fine when you use this code in the "single line" input field
The issue Armando reported is explained in this thread. The values in the input are getting doubled before they run through the calculation.
Instead of using
$('.sum input').each(function () {
you would use
$('.sum input').filter(':visible').each(function () {
Noted, thanks for the update...
Hello Mazahir,
This is something easily accomplished with the use of Javascript. How you implement this calculation is up to you, as there are many ways to do it.
Laserfiche provides documentation in the Online Help files for Forms on how to do this calculation one type of way. Refer to the link below to try the recommended way to do this calculation.
Good Luck
hi to All
Thanks for all your support i found from Laserfiche Help sample code & modify as per my requirement and it is working fine.
Best Regards
Mazahir Naya