Reputation: 724
I have this code is JS
$(".datepicker").datepicker();
$(".datepicker-to").datepicker({
changeMonth: true,
changeYear: true,
maxDate: "0D"
});
that accepts date not beyond the current system date. Now for example I have two textbox that accepts date from and date to...Now I want the system to validate. Example I have entered in date from: 1-15-13(MMDDYY) and date to: 1-13-13...abviously it is not acceptable. Now how to filter this one?
Upvotes: 1
Views: 240
Reputation: 56509
jQuery Datepicker provides the ability to select the date range.
Try using the below code.
HTML:
<input id="fromDate" type="text"/>
<input id="toDate" type="text"/>
jQuery:
$('#fromDate').datepicker({
changeMonth: true,
changeYear: true,
onClose: function( selectedDate ) {
$( "#toDate" ).datepicker( "option", "minDate", selectedDate );
}
});
$('#toDate').datepicker({
changeMonth: true,
changeYear: true,
onClose: function( selectedDate ) {
$( "#fromDate" ).datepicker( "option", "maxDate", selectedDate );
}
});
Check this JSFiddle.
Upvotes: 2
Reputation: 17194
Here you go:
HTML:
<input id="from" type="text"/>
<input id="to" type="text"/>
JQUERY:
$(function () {
$("#from").datepicker({
defaultDate: "+1w",
changeMonth: true,
onClose: function (selectedDate) {
$("#to").datepicker("option", "minDate", selectedDate);
}
});
$("#to").datepicker({
defaultDate: "+1w",
changeMonth: true,
onClose: function (selectedDate) {
$("#from").datepicker("option", "maxDate", selectedDate);
}
});
});
Upvotes: 0