views:

372

answers:

2

Hi,

I'm using ui.datepicker.js

In my edit form I have 2 calendars that have their own function.

Calendar A : is the date that the invoiced is created Calendar B : is the date for next billing Bill_freq is the field where is set the billing frequency (every 1 month, 3 months, 6 months, 12 months)

What I want to do is when date is changed on Calendar A, Calender B will be updated automatically to a date base on Bill_freq field.

Thanks for your help!

A: 

try something like onchange="$('#Calenderb').val($('#Calendera').val())"

mnml
Hi mnml,How to set the date base on Bill_freq value?
lena
+1  A: 
$('#myCalendarA').datepicker({
   //other options here
   onSelect: function(dateText, inst) {  
       //pick the value you need
       var billFreq = $('#Bill_freq').val();  
       //do some calculation with dateText (selected date in CalA) and billFreq
       var newDate = dateText + billFreq;  //beware date calc in JS is hard to master
       //sets the date for Calendar B           
       $('#myCalendarB').datepicker('setDate', newDate) ;
   }
});
Alex Bagnolini
Hi Alex, I have tried your code without success...the calendar stop working after Any clue?
lena
You have to add the `onSelect` parameter in the first call you do to activate datepicker.
Alex Bagnolini
Hi, I have 4 calendars ont his form, the first 2 are regular calendar.. Do you mean I have to add onSelect on the first one?
lena
Yes, because it is the one that, when changed, will change the second calendar. Is it what you wanted?
Alex Bagnolini
yes this is what I need. I will make other tests today maybe I'm missing something. There are 2 others calender on the form that are regular single calender that are in the begginning of the form maybe this is what causing the problem...
lena
Do I need to give a second class name for both calender or use the same class name?
lena
Calendars are pretty unique elements in forms. I usually give them all different IDs, rather than using classes to select them. As in the above example, `#myCalendarA` is the first one, `#myCalendarB` is the second one. You have to add the *special* `onSelect` only in `myCalendarA`. The other ones can work as before (be sure to use a different `.datepicker` call for them!)
Alex Bagnolini
Ok I see, I have fixed it, now calendar are ok, but it still doing nothing to CalendarB if I changed CalenderA.The value for billFreq are arrays and stored in the BD like this 30 for 30 days.
lena