Calculate fields

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

nigel created the topic: Calculate fields

Hi,

I have followed the tutorial and all works well but I am trying to make a work timesheet and therefore want to calculate the amount of hours and minutes worked,

number1 = 09:15
number2 = 16.45
Total = 9.2999

Any idea how I can make it calculate hours and minutes?

Thanks

nigel
#239360
  • Posts: 3125
  • Karma: 104
  • Thank you received: 410

mihaela replied the topic: Calculate fields

Hello,

Here is the Actionscript for the "number1" element that will calculate the number of hours and minutes between the time entered in field "number1" and "number2":
function ff_number1_action(element, action)
{

valuestart = ff_getElementByName('number1').value;
valuestop = ff_getElementByName('number2').value;

var date_now = new Date("01/01/2007 " + valuestart);
var date_future = new Date("01/01/2007 " + valuestop);

var diffMs = (date_future - date_now); // milliseconds between now & Christmas
var diffDays = Math.floor(diffMs / 86400000); // days
var diffHrs = Math.floor((diffMs % 86400000) / 3600000); // hours
var diffMins = Math.round(((diffMs % 86400000) % 3600000) / 60000); // minutes

ff_getElementByName('Total').value = diffHrs + " hours and " +  diffMins + " minutes";

} // ff_number1_action
NOTE: Adjust the names of the elements in the code if they are not "number1", "number2" and "Total".

Make sure that you check the "Change" as Action in the Actionscript section.

The code for the "number2" element should be:
function ff_number2_action(element, action)
{

valuestart = ff_getElementByName('number1').value;
valuestop = ff_getElementByName('number2').value;

var date_now = new Date("01/01/2007 " + valuestart);
var date_future = new Date("01/01/2007 " + valuestop);

var diffMs = (date_future - date_now); // milliseconds between now & Christmas
var diffDays = Math.floor(diffMs / 86400000); // days
var diffHrs = Math.floor((diffMs % 86400000) / 3600000); // hours
var diffMins = Math.round(((diffMs % 86400000) % 3600000) / 60000); // minutes

ff_getElementByName('Total').value = diffHrs + " hours and " +  diffMins + " minutes";

} // ff_number2_action

Let me know whether this is working as you wanted.

Regards,

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

nigel replied the topic: Calculate fields

hi, when I enter data into number1 on the form "NaN hours and NaN minutes" appears in the Total field
#239380
Moderators: ForumSupporttomeperica
Time to create page: 0.062 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