i am working on an already built program with a lot of classes and jscripts. the issue is the code has 3 dropdownlist's month, date, year. I need to remove the date one and passa static "01" value. here's the code for validating date in javascript -
function Validate_date(sender, args) {
var m = document.getElementById(sender.id.replace(/cv/, "m"));
var d = document.getElementById(sender.id.replace(/cv/, "d"));
var y = document.getElementById(sender.id.replace(/cv/, "y"));
if (isDate(m.value, d.value, y.value)){
var myDate = new Date();
myDate.setFullYear(y.value, m.value - 1, d.value);
var today = new Date();
today.setDate(today.getDate()-30);
args.IsValid = (myDate >= today);
}
else{
args.IsValid = false;
}
}
now the isdate function -
function isDate(strMonth, strDay, strYear) {
if (strDay.charAt(0) == "0" && strDay.length > 1) strDay = strDay.substring(1);
if (strMonth.charAt(0) == "0" && strMonth.length > 1) strMonth = strMonth.substring(1);
for (var i = 1; i <= 3; i++) { if (strYear.charAt(0) == "0" && strYear.length > 1) strYear = strYear.substring(1); }
month = parseInt(strMonth);
day = parseInt(strDay);
year = parseInt(strYear);
if (strYear.length != 4 || year == 0) return false;
if (strMonth.length < 1 || month < 1 || month > 12) return false;
if (strDay.length < 1 || day < 1 || day > 31 || (month == 2 && day > daysInFebruary(year)) || day > DaysArray(12)[month]) return false;
return true;
}
the problem is for dropdownlist when i give value= "01", it crashes on this line -
if (isDate(m.value, d.value, y.value)){ in the validate function
dropdownlist code -
<asp:DropDownList ID="EXP_d" runat="server" visible="false">
<asp:ListItem Value="01">DD<ListItem>
<asp:DropDownList>
how can i pass the static value 01 from EXP_d (date) dropdownlist?