Calculation process between two...

User 2611054 Photo


Registered User
33 posts

Hi,

May i have help on my form :|
I have forme with tow numbers filds .
fild 1

fild 2

I would like form to calculate two results for you from the fields 1 and fields 2

The first result = ((fild1+fild2 )-(fild1*0.04))/0.375

in case of the first result have decimals numbers i need the form add amount to make the result amount without decimals . The first result must be always add amount to remove the decimals never deduct any sums, no matter how small.

The second result =IF(8>=(fild1*0.05),8/0.375,(fild1*0.05)/0.375)

in case of the second result have decimals numbers i need the form deduct the decimals amount to make the result without decimals . The second result must be always deduct the decimals never add any sums, no matter how small.

Thank you
User 187934 Photo


Senior Advisor
19,126 posts
Online Now

Hi Zizo,
Can I have a link to your form so I can customize the script to your inputs
Where are you putting the results?
I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.

This is a site I built for my work.(RSD)
http://esmansgreenhouse.com
This is a site I built for use in my job.(HTML Editor)
https://pestlogbook.com
This is my personal site used for testing and as an easy way to share photos.(RLM imported to RSD)
https://ericrohloff.com
User 2611054 Photo


Registered User
33 posts

Hi Eric,

Thank you for your reply.

Actually i did not publish any form yet.

Cuz still not customized.

Regarding the results fields i would like to make it hidden fields. The result will shows up only in the confirmation page after submitting the forms.

It's mean the form will show only tow fields
Feild 1 & Feild 2
User 187934 Photo


Senior Advisor
19,126 posts
Online Now

What about Rounding any values? Do you want to round or just remove decimals?
Can you also explain the result 2, as it's not making sense to me.
The second result =IF(8>=(fild1*0.05),8/0.375,(fild1*0.05)/0.375)

I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.

This is a site I built for my work.(RSD)
http://esmansgreenhouse.com
This is a site I built for use in my job.(HTML Editor)
https://pestlogbook.com
This is my personal site used for testing and as an easy way to share photos.(RLM imported to RSD)
https://ericrohloff.com
User 2611054 Photo


Registered User
33 posts

Hi Eric,

I would like to Clearfai about the form

I would like to use the form to calculate airline Tickets net fare after dudect our commission and get the amount of cost of any tickets that i purchase from airline . also calculate the refund fee of the ticket in case of cancel the tiecket.

The Tickets of Yemenia airline have base fare and Texas.

So our form have tow fields
Feild 1 = the base fare of Ticket
Feild 2 = the Texas fare of tickets

According to the airline policy we get our commission when we sell tickets 4% from the base fare only.

So i usually use XLS fail and this function to calculate the net fare

(fild1+fild2 )-(fild1*0.04) = net fare

After i get the net fare i convert it from BHD to USD currency by using this
Net fare /0.375

Note :
1 USD = 0.378 BHD

So fainal functions will be
((fild1+fild2 )-(fild1*0.04))/0.375

in case of refund the refund fee will be 5% from base fare or 8 BHD whichever is higher.

So i usually use this XLS fail and function to get the refund fee and convert it from BHD to USD

=IF(8>=(fild1*0.05),8/0.375,(fild1*0.05)/0.375)
It's mean if 5% of base fare more than 8
Print 5% as refunds fee
If the 5% less than 8 BHD put 8 as refund fee.

So

My form have to collect tow results from tow fields.

Regarding the decimals number on results its ok if we get 2 decimals numbers after Rounding any values.

I hope you understand and help me with this

User 187934 Photo


Senior Advisor
19,126 posts
Online Now

Version one.
No fields hidden yet for testing.
Lets make sure I understand the math.
https://ericrohloff.com/coffeecup/ccfor … o-results/
I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.

This is a site I built for my work.(RSD)
http://esmansgreenhouse.com
This is a site I built for use in my job.(HTML Editor)
https://pestlogbook.com
This is my personal site used for testing and as an easy way to share photos.(RLM imported to RSD)
https://ericrohloff.com
User 2611054 Photo


Registered User
33 posts

YES, this the correct math :D

but, If you could make result 1 rounding up the values .
result2 rounding down the values this will be exactly what i need.
if you could not , let the result be with 2 dicimal numbers in bothe results fields .
User 187934 Photo


Senior Advisor
19,126 posts
Online Now

Check this out now.
https://ericrohloff.com/coffeecup/ccfor … o-results/
I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.

This is a site I built for my work.(RSD)
http://esmansgreenhouse.com
This is a site I built for use in my job.(HTML Editor)
https://pestlogbook.com
This is my personal site used for testing and as an easy way to share photos.(RLM imported to RSD)
https://ericrohloff.com
User 2611054 Photo


Registered User
33 posts

Yes , this is it :):):)

perfect .

could you please show me how did you do that ??
User 187934 Photo


Senior Advisor
19,126 posts
Online Now

Place a html element in your form.
Paste this code into it after you make any adjustments needed for it to match your input names and item id's. The item id targets are what hides the inputs.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>var jQ = $.noConflict(true);
jQ(document).ready(function(){
// ver 2
jQ("#item3").css("display", "none");// Change #item3 to match your item id holding result1
jQ("#item4").css("display", "none"); // Change #item4 to match your item id holding result2
jQ("input[name='fild1'],input[name='fild2']").keyup(function(){
var fild1 = parseFloat(jQ("input[name='fild1']").val());
var fild2 = parseFloat(jQ("input[name='fild2']").val());
if(jQ.isNumeric(fild1) && jQ.isNumeric(fild2) && fild1 !='' && fild2 != '' ){
//var result1 = (((fild1+fild2 )-(fild1*0.04))/0.375).toFixed(2);
var result1 = Math.ceil((((fild1+fild2 )-(fild1*0.04))/0.375)*100)/100;
var result2 = 0;
jQ("input[name='result1']").val(result1);
if((fild1*0.05) <=8){
result2 = Math.floor((8/0.375)* 100) / 100;
}
else{
result2 = Math.floor(((fild1*0.05)/0.375)* 100) / 100;
}
jQ("input[name='result1']").val(result1);
jQ("input[name='result2']").val(result2);
}
else{
jQ("input[name='result1']").val('');
jQ("input[name='result2']").val('');
}
});
});</script>

I named my inputs fild1 and fild2 and
result1 and result2
The div item id's in my form containing the result inputs were item3 for result1 and item4 for result2.
Your form will probably have different id's for the div's holding the two result inputs. Look at your source code to determine this and change the code where commented.
You can change the other input targets to match your form if they are different from mine or just change the name of your inputs to match mine in the code.

Field 1 = fild1
Field 2 = fild2
Result 1 = result1
Result 2 = result2
if your inputs have different names adjust these jQ targets in the code to match your input names.
jQ("input[name='fild1']")
jQ("input[name='fild2']")
jQ("input[name='result1']")
jQ("input[name='result1']")

I adjusted my form to hide the two inputs and alert the two results.
You'll also need to remove the script wrapping the iframe code provided by the Form builder on export.
I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.

This is a site I built for my work.(RSD)
http://esmansgreenhouse.com
This is a site I built for use in my job.(HTML Editor)
https://pestlogbook.com
This is my personal site used for testing and as an easy way to share photos.(RLM imported to RSD)
https://ericrohloff.com

Have something to add? We’d love to hear it!
You must have an account to participate. Please Sign In Here, then join the conversation.