• 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: Please help - JS skills needed (script needed)

Please help - JS skills needed (script needed) 11 years 6 months ago #25369

  • josh.thomson
  • josh.thomson's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 19
  • Thank you received: 2
I have been making various forms with great success.

However... the form I am trying to make in this moment requires a text field that may get altered depending on the value held in another field.

here's what the form does:

You select a date (Date away from)
You select a second date (Date away until)
Text box uses JS to work out the difference between the dates above and gives an int value
Checkbox with the caption "Halfday?"


My problem:
I want the Checkbox to only show if the value held in the textbox is '1', so that people can only set the field as a 'halfday' if the date away is just for one day.

I have searched every grain of sand on this earth for a solution... I am having problems finding one

Here's my JS code so far... I found It on one of these forum posts (credits to the original owner)

▐▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▌
<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 == 'cal3_1' && RSFormProCalendars[3]['DatesRequiredTo'].getSelectedDates() != '')
  date2 = new Date(RSFormProCalendars[3]['DatesRequiredTo'].getSelectedDates());
 
if(calendar.myid == 'cal3_0' && RSFormProCalendars[3]['DatesRequiredFrom'].getSelectedDates() != '')
  date2 = new Date(RSFormProCalendars[3]['DatesRequiredFrom'].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);
  document.getElementById('NumberofDays').value = days;
  //this will assign the days difference value to our textbox.
}
 
return true;
}
</script>
 
▐▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▌

I was thinking... perhaps a variable if statement using CSS display "" / display "none" styles?

But cannot get this to work


Any contribution to try and help will be greatly appreciated!

Thanks,
Josh Thomson
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!