Calculating on Form

  • nigel
  • Topic Author
  • Offline
  • Gold Boarder
  • Gold Boarder
  • Posts: 161
  • Thank you received: 1

nigel created the topic: Calculating on Form

After following your tutorial I have a couple of questions

I have made a timesheet which people will enter Start time, Finish time and then there is a calculated field to work out the number of hours for that day.

I now wish to add all those calculated fields into a grand total of hours worked, how do I do that?

Also how can I select that the calculated number only shows two decimal points?
#239363
  • Posts: 3125
  • Karma: 104
  • Thank you received: 410

mihaela replied the topic: Calculating on Form

Hello,

One option is to make the calculation of grand total in the Initialization script as follows.

Go to the Advanced properties of your form > More options > Scripts and in the Initialization section set Type to Custom. In the code area that appears put code like this:
function ff_FORMNAME_init()
{
setInterval('calc()', 500);
} // ff_FORMNAME_init

function calc() {
var grandsum = 
    Number(ff_getElementByName('firstField').value) + 
    Number(ff_getElementByName('secondField').value) + 
    Number(ff_getElementByName('thirdField').value);

    ff_getElementByName("Grand_total").value = Number(grandsum).toFixed(2);
}
NOTE: In the code above, replace FORMNAME with the name of your form.
Also, replace "firstField", "secondField" and "thirdField" with the Names of the fields that should be included in the calculation.

Another option is to add this line of code to the Actionscript of EACH element whose value is included in the calculation:
    ff_Grand_total_action();

In the "Grand_total" field you would have to put code like this:
function ff_Grand_total_action(element, action)
{
var grandsum = 
    Number(ff_getElementByName('firstField').value) + 
    Number(ff_getElementByName('secondField').value) + 
    Number(ff_getElementByName('thirdField').value);

    ff_getElementByName("Grand_total").value = Number(grandsum).toFixed(2);
} // ff_Grand_total_action

NOTE: In this code, it is assumed that the name of the total field is "Grand_total".

The code provided also rounds the total number to two decimal places.

Let me know whether you have managed to apply this to your form.

Regards,

Mihaela
#239376
Moderators: ForumSupporttomeperica
Time to create page: 0.056 seconds

New Icon Packs Category!

Crosstec is now offering icon packs.

If you are a paying subscriber, icon packs are automatically added to your account.

Check out our icon packs page!

Live Support Chat Opened!

Join our Discord chat here to receive live support and talk directly to the team!

Summer Sale!

50% discount on all of our extension subscription plans, templates and icon packs!

Get Your Subscription 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 for just 49! (Summer Sale)

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!

Live Support Chat Opened!

Join our Discord chat here to receive live support and talk directly to the team!

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