Hi. I'm a new user of jQuery and of JS in general. I'm trying to
modify a script I found, for a different jQuery-based calendar widget,
here: 
http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/datePickerIntoSelects.html

The basic idea is that I have a hidden field #date_pick on which hangs
a button for a datepicker; I have three select fields, for day, month,
and year, and I want any changes I make to the datepicker to be
reflected in these fields. Conversely, I want any changes made to
these fields to be reflected in the datepicker.

The code I came up with was this:

---
$(function()
  {
      // initialise the "Select date" link
      $('#date_pick').datepicker(
                                 {
                                     showOn: 'button',
                                         buttonImage: 
'../static/images/calendar.gif',
                                         buttonImageOnly: true,
                                         onClose: function(date) {
                                         updateSelects(date)
                                             }
                                 }
                                  );
      var updateSelects = function(selectedDate)
          {
              var d = selectedDate.getDate();
              var m = selectedDate.getMonth();
              var y = selectedDate.getYear();
              ($('#date_purch_day')[0]).selectedIndex = d - 1;
              ($('#date_purch_month')[0]).selectedIndex = m;
              ($('#date_purch_year')[0]).selectedIndex = y - 2005;
          }

      // listen for when the selects are changed and update the picker
      $('#date_purch_day, #date_purch_month, #date_purch_year').change
(function()
                {
                    var d = new Date(
                                     $('#date_purch_year').val(),
                                     $('#date_purch_month').val()-1,
                                     $('#date_purch_day').val()
                                     );
                    $('#date_pick').datepicker('setDate',d);
                }
                                                                       );
});
---
According to the docs for onClose, "The function receives the selected
date as a Date", so I assumed that meant a JS Date object, and I
assumed that this Date object is what is being passed to the
updateSelects function, where it is picked up as selectedDate.
However, when I run this and change a date in the picker, I get the
error "selectedDate.getDate is not a function." I've fiddled around
with a few things, to no avail, and sought help in the #jquery IRC
channel, also unsuccessfully.

I may well be understanding how variables are passed to and from
functions, or I may be misunderstanding something else. In any event,
I'd be very grateful for any help to make this work, either in regard
to this one specific issue, or to other aspects of this code.

Thanks.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jQuery UI" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/jquery-ui?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to