Jquery date picker divided into several fields

I have a normal jQuery work day. But I want to pass it to a set of selectboxes, not a single text box. I had a successful submission of it in one selection field with a specific format, but I'm not sure how to submit all three to different fields with different formats.

$(document).ready(function(){
  $("#search_startdate").datepicker({showOn: 'button', 
                                     buttonImage: '/images/cal/calendar.gif', 
                                     buttonImageOnly: true, 
                                     minDate: 0, 
                                     maxDate: '+6M +10D', 
                                     showAnim: 'fadeIn',
                                     altField: '#startdate_month', 
                                     altFormat: 'MM',
                                     altField: '#startdate_day',
                                     altFormat: 'dd'});
    //$("#datepicker").datepicker({showOn: 'button', buttonImage: 'images/calendar.gif', buttonImageOnly: true});

});

This does not work, it works in the last field, but ignores the first. If I delete the second set of altField and altFormat lines, the first works.

I also tried putting them in a series,

altField: '#startdate_month', '#start_day', altFormat: 'MM', 'dd'

The problem is the same as here:

http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Jquery/Q_24767646.html

Any ideas?

Thanks,

+5
source share
3

, , onClose .

$(document).ready(function(){
  $("#search_startdate").datepicker({showOn: 'button', 
                                     buttonImage: '/images/cal/calendar.gif', 
                                     buttonImageOnly: true, 
                                     minDate: 0, 
                                     maxDate: '+6M +10D', 
                                     showAnim: 'fadeIn',
                                     altField: '#startdate_month', 
                                     altFormat: 'MM',
                                     onClose: function(dateText,picker) {
                                                 $('#startdate_day').val( dateText.split(/\//)[1] );
                                              }
                                    });
});
+8

, :

$('#datePickerField').datepicker({
    onClose: function (dateText) {
                var objDate = new Date(dateText);
                $('#year_field').val(dateText.length ? objDate.getFullYear() : '');
                $('#month_field').val(dateText.length ? objDate.getMonth() + 1 : '');
                $('#day_field').val(dateText.length ? objDate.getDate() : '');
            }
});

, , , , , :

$('#year_field,#month_field,#day_field').change(function() {
    $('#datePickerField').datepicker('setDate', new Date(
        parseInt($('#year_field').val(), 10),
        parseInt($('#month_field').val(), 10) - 1,
        parseInt($('#day_field').val(), 10)));
});
0

just leaving the answer here for future reference, here is a sample of how I did it:

$("#departDate").datepicker({
    onClose: function( selectedDate ) {

        // use split() to break down the [MM/DD/YYYY] format
        // populate each into multiple field

        $('#departDateDay').val( selectedDate.split(/\//)[1] ); // day
        $('#departDateMonth').val( selectedDate.split(/\//)[0] ); // month
        $('#departDateYear').val( selectedDate.split(/\//)[2] ); // year
    }
})
0
source