Date before the current date should not be selected
I am trying to sho开发者_如何学Gow a popup message when any date before current day is clicked in the calendar? This is the function that has the date the user has clicked. setCalendarControlDate(year, month, day) has the date what user has selected. How can i compare the dates and show the error.
function setCalendarControlDate(year, month, day) {
calendarControl.setDate(year, month, day);
var arguments = "changeDataGrid;day=" + day;
arguments += ";month=" + month;
arguments += ";year=" + year;
// arguments += ";rowId=" + rowId;
arguments += ";" + rowId;
arguments += ";";
document.getElementById(targetControlId.id).value = arguments;
document.forms[0].submit();
}
var selectedDate = new Date(year, month-1, day);
var valid = selectedDate >= new Date();
// If today was 12th April 2011
year = 2011;
month = 4;
day = 13;
var selectedDate = new Date(year, month-1, day);
var valid = selectedDate >= new Date();
valid ; //# => true
year = 2011;
month = 4;
day = 11;
selectedDate = new Date(year, month-1, day);
var valid = selectedDate >= new Date();
valid ; //# => false
精彩评论