A
avcc
Hello,
If have a HTML form where a user can type a date, this date must be today,
or in the future. To test it i made this javascript
function validate()
{
var cdate_h = form.elements["cdate"].value;
if (cdate_h.length == 0)
{
alert("completion date");
return;
}
calDate = new Date();
var day = calDate.getDate();
var month = calDate.getMonth() + 1;
var year = calDate.getFullYear();
var today = year * 10000 + month * 100 + day;
var pos1=cdate_h.indexOf("-"); // date
format YYY-MM-DD
var pos2=cdate_h.indexOf("-",pos1+1);
var strYear=cdate_h.substring(0,pos1);
var strMonth=cdate_h.substring(pos1+1,pos2);
var strDay=cdate_h.substring(pos2+1);
var userdate = strYear * 10000 + strMonth * 100 + strDay;
if (parseFloat(userdate) < parseFloat(today))
{
alert ("Completion date can not be in the past");
return;
}
}
When I debug the variables userdate and today it looks fine, but the if
statement does not work WHY ??????
Can someone help me ? Many thanks in advance.
Richard
If have a HTML form where a user can type a date, this date must be today,
or in the future. To test it i made this javascript
function validate()
{
var cdate_h = form.elements["cdate"].value;
if (cdate_h.length == 0)
{
alert("completion date");
return;
}
calDate = new Date();
var day = calDate.getDate();
var month = calDate.getMonth() + 1;
var year = calDate.getFullYear();
var today = year * 10000 + month * 100 + day;
var pos1=cdate_h.indexOf("-"); // date
format YYY-MM-DD
var pos2=cdate_h.indexOf("-",pos1+1);
var strYear=cdate_h.substring(0,pos1);
var strMonth=cdate_h.substring(pos1+1,pos2);
var strDay=cdate_h.substring(pos2+1);
var userdate = strYear * 10000 + strMonth * 100 + strDay;
if (parseFloat(userdate) < parseFloat(today))
{
alert ("Completion date can not be in the past");
return;
}
}
When I debug the variables userdate and today it looks fine, but the if
statement does not work WHY ??????
Can someone help me ? Many thanks in advance.
Richard