jonthornton / Datepair.js

A javascript plugin for intelligently selecting date and time ranges, inspired by Google Calendar.
https://www.jonthornton.com/Datepair.js
358 stars 87 forks source link

Datepair - call another function after updated to calculate total hours #82

Closed milacay closed 7 years ago

milacay commented 7 years ago

Hi,

I know it is not a bug in your library, but the issue somewhere in my code. I have posted on jsfiddle.net (link below). What I try to accomplish is that when the page loads or any date fields changed, the field Total Hours shows the hour differences based on the Start Date/Time and End Date Time.

I do have the Javascript function called "updateEstHrs()" there (see line# 38 - 53). I tried to call this function after date/time changed to update total hours, but not success (see line# 32 - 34). Please help.

(https://jsfiddle.net/milacay/3rg9x7zt/6/)

Nevario commented 7 years ago

Hi,

You had quite a few selectors wrong (#tableExample instead of #basicExample). Also you can listen to the rangeSelected event in datepair, rather than trying to listen to the timepicker directly.

The last thing is that trying to work out the duration of dates + times can be quite difficult. Luckily datePair provides a method getTimeDiff() that does this for you.

See an updated fiddle for a working example:

https://jsfiddle.net/tdmohr/3rg9x7zt/9/

Tim

milacay commented 7 years ago

It works perfect.. Thank you so much for helping and I am really appreciated your time. Sorry, I am new to Jquery stuff, but love to learn.