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
2010-08-20 15:37:08
@ 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
2010-08-20 15:54:34
you don't need two bindings on the startDate. both of them can be combined to one. Check the edit
Teja Kantamneni
2010-08-20 16:02:57
@ 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
2010-08-20 16:17:43
You have to bind one more picker to end date too. Check edit one more time
Teja Kantamneni
2010-08-20 17:36:26
@ 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
2010-08-23 12:09:08
@hersh -- can you post your HTML and js code so far. Preferably in http://jsfiddle.net/
Teja Kantamneni
2010-08-23 12:59:05
@ Teja Kantamneni -- http://jsbin.com/epepo4/3/edit
hersh
2010-08-23 13:45:57