I am making an employee vacation request form. I have two calendars that, through a script, populate a text box with the total number of days off. Before I had this, users would manually enter their total number of days off. I thought I would automate it. The problem is, once I add this script, all calculations stop working. I have a calculation that multiplies the total number of days off by the total number of vacation hours per day to fill a text box with the total number of hours requested. Why would scripts stop calculations from working? I have noticed that this happens with other custom scripts as well. I will attach the script as a text file in case it helps.
Here is the working script:
<script type="text/javascript">
function calculateDate(date1, date2){
//our custom function with two parameters, each for a selected date
diffc = date1.getTime() - date2.getTime();
//getTime() function used to convert a date into milliseconds. This is needed in order to perform calculations.
days = Math.round(Math.abs(diffc/(1000*60*60*24)));
//this is the actual equation that calculates the number of days.
return days;
}
function rsfp_onSelectDate(date, type, args, calendar){
//RSForm!Pro specific calendar function.
//args = object, containing the date in the exact format needed for the above getTime() function.
//calendar = object, containing various properties of the calendar.
argsstr = String(args);
spldate = argsstr.split(",");
date1 = new Date(spldate[0],spldate[1]-1,spldate[2]);
//the selected date converted into proper format for calculations
date2 = '';
if(calendar.myid == 'cal7_0' && RSFormPro.YUICalendar.calendars[7]['VEnd'].getSelectedDates() != '')
date2 = new Date(RSFormPro.YUICalendar.calendars[7]['VEnd'].getSelectedDates());
if(calendar.myid == 'cal7_1' && RSFormPro.YUICalendar.calendars[7]['VStart'].getSelectedDates() != '')
date2 = new Date(RSFormPro.YUICalendar.calendars[7]['VStart'].getSelectedDates());
//the above if clauses, check from which of the two calendars the selection was made and assigns the ending date
//only when both dates are selected.
if(date2 != ''){
//the calculation will be done when the dates are selected.
days = calculateDate(date1, date2);
dayfinal = days+1;
document.getElementById('DayOff').value = dayfinal;
//this will assign the days difference value to our textbox.
}
return true;
}
</script>