Reputation: 612
I'm using three drop down controls to ask the user to select birth date and to validate the date after selection I have called Java script code on all three drop down "onChange" events.
The function checks the maximum date of month and set the date into drop down if the date is selected more than the maximum date of the month.
It works but not displaying the current selection. Below is the complete javascript code:
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;
}
After the line "elementRef.options[i].selected = true;" I have put alert and checked that selection of value works perfectly but not showing on the page.
Anyone can please help?
Thanks, Dhaval
Upvotes: 1
Views: 556
Reputation: 612
I apologies, I have created separate application and found it is working. The problem is with the jQuery used for theming these drop down controls.
Upvotes: 1