Trouble creating calculations using subtotals

  • derost
  • derost's Avatar Topic Author
  • Offline
  • Senior Boarder
  • Senior Boarder
  • Posts: 43
  • Thank you received: 0

derost created the topic: Trouble creating calculations using subtotals

Hello,
So I've got a form that takes the input of various sized heaters (in BTUs), along with price of propane and the amount of usage and calculates the cost to run the heaters.

What works:
- Selecting the number of different sized heaters then calculates the total amount of BTUs being used (totalbtu).

What kind of works:
- Calculating the cost per week based on the cost of propane and the hours of usage. This only works when I link it to a manual entry (labeled test amount). What should happen is that the value of the (totalbtu) is used instead of the (test).
- Sometimes the result is a nice number like $10.12, (with input values of 11000, 20, 15); and sometimes it comes out as $6.746,666,666,666,666 (with input values of 11000, 20, 10)

What doesn't work:
- Calculating the total per year. This would be the total cost per week (perweek) times the number of weeks being used (weeks). The (perweek) would be a subtotal and I can't get to use that in a calculation.

I have attached the form along with a copy of the code I was trying that doesn't work. (Not sure of the best way to view code on the forum)

File Attachment:

File Name: mushroom_2...2-26.zip
File Size:47 KB

File Attachment:

File Name: mushroomsc...work.zip
File Size:0 KB


Thanks in advance for your help
#233002
Attachments:
  • Posts: 1965
  • Karma: 67
  • Thank you received: 238

mihaela replied the topic: Trouble creating calculations using subtotals

Hello,

Sorry for the late response, Crosstec Support staff was on collective holiday vacation, as noted in the forum.

To make the calculation for total year work navigate to your form's Advanced options > More options > Scripts and in the Initialization script section set Type to Custom.

In the code area below put code like this:
function ff_copy_mushroom1_init()
{  setInterval('calculateperyear()',500);
} // ff_copy_mushroom1_init


function calculateperyear() {

 var perweek = ff_getElementByName('perweek').value.replace("$","");
 perweek = perweek.replace(/,/g, '')
 console.log(perweek);
ff_getElementByName('peryear').value = Number(perweek) * Number(ff_getElementByName('weeks').value);
}

That should do the trick. Also, I suggest that you remove the addCommas function, because it adds commas in decimal places if I understood correctly and that is why you get a result like this "$6.746,666,666,666,666".

Furthermore, if you try to use "totalbtu" field's value in calculation it won't work because of the BTU so you can remove it with the appropriate code. Also, the comma sign makes the calculation not work so I suggest you don't use the addCommas function.

Let me know whether this helped.
If you have more questions, feel free to ask.

Regards,

Mihaela
#233071
Moderators: ForumSupporttomeperica
Time to create page: 0.062 seconds

Community Reward

Help us to create new extensions and plugins! With only $5 you help us a lot and get unlimited download access to all of our products, professional support and even more. Get your reward now!

Read More Here

News and Updates

Get informed about new downloads, updates and more in our News and Updates newsletter.

All Extensions Subscription

Get 1 year access to all of our current and future products and 1 year of professional support -- 99€

No support per domain or website installation limits! Includes all of our current and future Joomla!® extensions, Joomla!® templates for the duration of your membership. This means, by purchasing an All Extensions Subscription you'll have it all covered!

Get it from here

3rd Party Discount - 25% Off

We help you to keep your costs under control. If you are a new member and purchased a form building tool from a different form vendor, then you'll get a 25% discount on our subscription plans.

How to receive the discount:

Send us a quick email to sales@crosstec.org with a proof of purchase (for example a paypal receipt), await payment instructions and enjoy your membership!

Community Reward

Help us to create new extensions and plugins! With only $5 you help us a lot and get unlimited download access to all of our products, professional support and even more. Get your reward now!

Read More Here