views:

38

answers:

1

I have a start and stop textbox field which triggers jquery calendar. I want to know whether it is possible to achieve when I select a date on the start, will populate the same on the stop?

+2  A: 

use onSelect callback to copy the start date into end date field.

$('#startDate').datepicker({
   onSelect: function(dateText, inst) { 
      $('#endDate').val($(this).val());
   }
});

EDIT::

$('#startDate).datetimepicker({
      ampm: true, 
      minDate: 0,
      onSelect: function(dateText, inst) { 
          $('#endDate').val($(this).val());
       }
}); 

EDIT for end date::

$('#endDate).datetimepicker({ ampm: true });

the two edits combined will make your entire code. Also you may want to add a if condition in onSelect to check if there is a value already in endDate so that you won't accidentally overwrite it.

Teja Kantamneni
@ Teja Kantamneni -- sorry, would datetimepicker have the same effect as what you described? I did get an alert when I select a date but still no luck.$('#startDate).datetimepicker({ ampm: true, minDate: 0 }); $('#endDate).datetimepicker({ ampm: true }); $('#startDate).datetimepicker({ onSelect: function(dateText, inst) { alert("ON"); $('#endDate).val($(this).val()); } });
hersh
you don't need two bindings on the startDate. both of them can be combined to one. Check the edit
Teja Kantamneni
@ Teja -- ok, this gets me on the right track but now this wont let me select a date in the end date field if I wanted to change it. For example click in the end date field to bring up the calendar.
hersh
You have to bind one more picker to end date too. Check edit one more time
Teja Kantamneni
@ Teja Kantamneni -- for start date if I select 08/20/2010 with a time of 9:00 am, my end date only returns 08/20/2010. Do you have any idea why it isnt giving me the time also?
hersh
@hersh -- can you post your HTML and js code so far. Preferably in http://jsfiddle.net/
Teja Kantamneni
@ Teja Kantamneni -- http://jsbin.com/epepo4/3/edit
hersh