Advertisement
grappler

Untitled

Aug 18th, 2012
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(function() {
  2.  
  3.     // initialise the "Select date" link
  4.     $('#date-pick').datePicker(
  5.     // associate the link with a date picker
  6.     {
  7.         createButton: false,
  8.         startDate: '01/01/2005',
  9.         endDate: '31/12/2010'
  10.     }).bind(
  11.     // when the link is clicked display the date picker
  12.     'click', function() {
  13.         updateSelects($(this).dpGetSelected()[0]);
  14.         $(this).dpDisplay();
  15.         return false;
  16.     }).bind(
  17.     // when a date is selected update the SELECTs
  18.     'dateSelected', function(e, selectedDate, $td, state) {
  19.         updateSelects(selectedDate);
  20.     }).bind('dpClosed', function(e, selected) {
  21.         updateSelects(selected[0]);
  22.     });
  23.  
  24.     var updateSelects = function(selectedDate) {
  25.         var selectedDate2 = new Date(selectedDate);
  26.         $('#d option[value=' + selectedDate2.getDate() + ']').attr('selected', 'selected');
  27.         $('#m option[value=' + (selectedDate2.getMonth() + 1) + ']').attr('selected', 'selected');
  28.         $('#y option[value=' + (selectedDate2.getFullYear()) + ']').attr('selected', 'selected');
  29.     }
  30.     // listen for when the selects are changed and update the picker
  31.     $('#d, #m, #y').bind('change', function() {
  32.         var d = new Date(
  33.         $('#y').val(), $('#m').val() - 1, $('#d').val());
  34.         $('#date-pick').dpSetSelected(d.asString());
  35.     });
  36.  
  37.     // default the position of the selects to today
  38.     var today = new Date();
  39.     updateSelects(today.getTime());
  40.  
  41.     // and update the datePicker to reflect it...
  42.     $('#d').trigger('change');
  43. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement