Currently, I have implemented a functionality using three drop down controls to prompt users to select their birth date. In order to validate the selected date, I have incorporated JavaScript code in all three drop down "onChange" events.
The function is designed to verify if the selected date exceeds the maximum date of the month and adjust the date in the drop down accordingly. However, despite functioning correctly, it fails to display the current selection. The complete JavaScript code is provided below:
function CheckValidDate() {
var getMonthControl = document.getElementById('<%= ddlBirthdateMonth.ClientID %>');
var SelectedMonth = getMonthControl.options[getMonthControl.selectedIndex].value;
var getYearControl = document.getElementById('<%= ddlBirthdateYear.ClientID %>');
var SelctedYear = getYearControl.options[getYearControl.selectedIndex].value;
var getDateControl = document.getElementById('<%= ddlBirthdateDate.ClientID %>');
var SelctedDate = getDateControl.options[getDateControl.selectedIndex].value;
if (SelectedMonth > 0 && SelctedYear > 0 && SelctedDate > 0) {
var month = SelectedMonth;
var NewDate = new Date(SelctedYear, month, 0);
var MonthMax = NewDate.getDate();
if (MonthMax <= SelctedDate) {
setDropDownList(getDateControl, MonthMax);
}
}
return false;
}
function setDropDownList(elementRef, valueToSetTo) {
var isFound = false;
for (var i = 0; i < elementRef.options.length; i++) {
if (elementRef.options[i].value == valueToSetTo) {
elementRef.options[i].selected = true;
isFound = true;
}
}
if (isFound == false)
elementRef.options[0].selected = true;
}
Upon further inspection, I noticed that the value selection functions properly, but the display on the page remains unchanged. Can anyone please assist me with this issue?
Regards, Dhaval