Page 2 of 5
Re: How to subtract dates to calculate nights
Posted: Sun Feb 23, 2020 11:14 pm
by kev1n
Add these 2 alert() functions to your code and tell me what you see in the message boxes.
Code: Select all
function subtractDateFields(f1, f2) {
alert('f1: ' + f1 + ' / ' + ' f2: ' + f2);
var f1 = $('#'+f1).val() .split("/");
var date1 = new Date(f1[2], f1[1] - 1, f1[0]);
var f2 = $('#'+f2).val() .split("/");
var date2 = new Date(f2[2], f2[1] - 1, f2[0]);
var timeDiff = Math.abs(date2.getTime() - date1.getTime());
alert('date1:' + date1+ ' / date2: ' + date2 + ' timeDiff: ' + timeDiff);
return Math.round(timeDiff / (2e3 * 3600 * 365.25));
}
Re: How to subtract dates to calculate nights
Posted: Mon Feb 24, 2020 8:35 am
by joecocs
nothing happens,
it's as if the onchange function is not happening.
is it because it's a nuDate object?
I changed to text entry but it doesn't work either
Re: How to subtract dates to calculate nights
Posted: Mon Feb 24, 2020 8:51 am
by kev1n
It works here. Add a simple alert('hello'). Does this show up?
Re: How to subtract dates to calculate nights
Posted: Mon Feb 24, 2020 9:03 am
by joecocs
Yes alert works
Re: How to subtract dates to calculate nights
Posted: Mon Feb 24, 2020 9:09 am
by kev1n
It looks like dureeprojets() is not getting called / found.
Add these two functions to the main form's custom code field, not a subform.
Code: Select all
function subtractDateFields(f1, f2) {
var f1 = $('#'+f1).val() .split("/");
var date1 = new Date(f1[2], f1[1] - 1, f1[0]);
var f2 = $('#'+f2).val() .split("/");
var date2 = new Date(f2[2], f2[1] - 1, f2[0]);
var timeDiff = Math.abs(date2.getTime() - date1.getTime());
return Math.round(timeDiff / (2e3 * 3600 * 365.25));
}
function dureeprojets(f1, f2) {
$('#Duree_Projets').val(subtractDateFields(f1,f2)); // <----- replace with your object id
}
Re: How to subtract dates to calculate nights
Posted: Mon Feb 24, 2020 9:21 am
by joecocs
I just tried by putting the code in the main form and removing that from the iFrame.
nothing.
I tried to put the code with the alerts, nothing.
my form consists of a main form and an iFrame with a form in it, and a third iFrame with another Form in the second:
Date calcul.png
in the third I will also have a date interval calculation in days

Re: How to subtract dates to calculate nights
Posted: Mon Feb 24, 2020 9:33 am
by joecocs
When in doubt I tried with another browser: firefox, safari and edge but nothing either
Re: How to subtract dates to calculate nights
Posted: Mon Feb 24, 2020 9:42 am
by kev1n
Are there no errors in the developer console? (F12)
Re: How to subtract dates to calculate nights
Posted: Mon Feb 24, 2020 9:55 am
by joecocs
Yes i have an error
Capture d’écran 2020-02-24 à 09.53.02.png
Re: How to subtract dates to calculate nights
Posted: Mon Feb 24, 2020 10:07 am
by kev1n
nuCalChoice() raises an error for some unknown reason. I would set a breakpoint in that function and execute step by step to figure out where the error occurs.
If you are not familiar with the developer console, read this:
https://developers.google.com/web/tools ... javascript