• 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!

TOPIC: Calculations stop working when scripts added

Calculations stop working when scripts added 8 years 11 months ago #35100

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>
Last Edit: 8 years 11 months ago by daspinwall.
The administrator has disabled public write access.
  • 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!