$(function() { // initialise the calendar icon link $('#date-pick1') .datePicker( // associate the link with a date picker { createButton:false, startDate:'01/01/2003', endDate:'31/12/2010' } ).bind( // when the link is clicked display the date picker 'click', function() { updateSelects($(this).dpGetSelected()[0]); $(this).dpDisplay(); return false; } ).bind( // when a date is selected update the SELECTs 'dateSelected', function(e, selectedDate, $td, state) { updateSelects(selectedDate); } ).bind( 'dpClosed', function(e, selected) { updateSelects(selected[0]); } ); $('#date-pick1').dpSetOffset(22, -155); var updateSelects = function (selectedDate) { selectedDate = new Date(selectedDate); var d = selectedDate.getDate(); var m = selectedDate.getMonth(); var y = selectedDate.getFullYear(); ($('#dia1')[0]).selectedIndex = d; ($('#mes1')[0]).selectedIndex = m+1; ($('#anio1')[0]).selectedIndex = y - 2003 + 1; } // listen for when the selects are changed and update the picker $('#dia1, #mes1, #anio1') .bind( 'change', function() { var d = new Date( $('#anio1').val(), $('#mes1').val()-1, $('#dia1').val() ); $('#date-pick1').dpSetSelected(d.asString()); } ); // default the position of the selects to today var today = new Date(); //($('#dia1')[0]).selectedIndex = today.getDate() ; //($('#mes1')[0]).selectedIndex = today.getMonth()+1; //($('#anio1')[0]).selectedIndex = today.getFullYear() - 2003 + 1; //($('#dia1')[0]).selectedIndex = 0;//modificado por mdiez para que el valor inicial de las fechas sea vacio //($('#mes1')[0]).selectedIndex = 0; //($('#anio1')[0]).selectedIndex = 0; // and update the datePicker to reflect it... $('#dia1').trigger('change'); }); $(function() { // initialise the calendar icon link $('#date-pick2') .datePicker( // associate the link with a date picker { createButton:false, startDate:'01/01/2003', endDate:'31/12/2010' } ).bind( // when the link is clicked display the date picker 'click', function() { updateSelects($(this).dpGetSelected()[0]); $(this).dpDisplay(); return false; } ).bind( // when a date is selected update the SELECTs 'dateSelected', function(e, selectedDate, $td, state) { updateSelects(selectedDate); } ).bind( 'dpClosed', function(e, selected) { updateSelects(selected[0]); } ); $('#date-pick2').dpSetOffset(22, -155); var updateSelects = function (selectedDate) { selectedDate = new Date(selectedDate); var d = selectedDate.getDate(); var m = selectedDate.getMonth(); var y = selectedDate.getFullYear(); ($('#dia2')[0]).selectedIndex = d ; ($('#mes2')[0]).selectedIndex = m+1; ($('#anio2')[0]).selectedIndex = y - 2003 + 1; } // listen for when the selects are changed and update the picker $('#dia2, #mes2, #anio2') .bind( 'change', function() { var d = new Date( $('#anio2').val(), $('#mes2').val()-1, $('#dia2').val() ); $('#date-pick2').dpSetSelected(d.asString()); } ); // default the position of the selects to today var today = new Date(); //($('#dia2')[0]).selectedIndex = today.getDate() ; //($('#mes2')[0]).selectedIndex = today.getMonth()+1; //($('#anio2')[0]).selectedIndex = today.getFullYear() - 2003 + 1; //($('#dia2')[0]).selectedIndex = 0;//modificado por mdiez para que el valor inicial de las fechas sea vacio //($('#mes2')[0]).selectedIndex = 0; //($('#anio2')[0]).selectedIndex = 0; // and update the datePicker to reflect it... $('#dia2').trigger('change'); });