0

I read many questions here but not find a solution for problem.

I have one page which has two dates and one text box. When I click on text box the difference of two dates in days will show on text box. But when I change the dates and click on text box it doesn't work.

Code

$('#totalNoOfLeave').click(function(){

    var date1 = new Date($('#leaveStartDate').getValue());
    var date2 = new Date($('#leaveEndingDate').getValue());
    var timeDiff = Math.abs(date2.getTime() - date1.getTime());
    var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24)); 
    $('#totalNoOfLeave').setValue(diffDays);

}); 

Please help.

7
  • I think the event should be focus Commented Jan 15, 2017 at 8:19
  • I can put alert inside function to debug. But also alert trigger once. Commented Jan 15, 2017 at 8:19
  • Could you create a minimal example to reproduce the problem, then? Commented Jan 15, 2017 at 8:20
  • I am using ProcessMaker, and here focus event is not trigger. It works with .click Commented Jan 15, 2017 at 8:21
  • Can you please tell me the way to call .click function whenever click on object in same page Commented Jan 15, 2017 at 8:25

1 Answer 1

1

Use this :

$('body').on('click', '#totalNoOfLeave', function () {

var date1 = new Date($('#leaveStartDate').getValue());
var date2 = new Date($('#leaveEndingDate').getValue());
var timeDiff = Math.abs(date2.getTime() - date1.getTime());
var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24)); 
$('#totalNoOfLeave').setValue(diffDays);

}); 
Sign up to request clarification or add additional context in comments.

1 Comment

thank you very much. Yes its working but I replace 'body' with form id

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.