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("completi on date");
return;
}
calDate = new Date();
var day = calDate.getDate ();
var month = calDate.getMont h() + 1;
var year = calDate.getFull Year();
var today = year * 10000 + month * 100 + day;
var pos1=cdate_h.in dexOf("-"); // date
format YYY-MM-DD
var pos2=cdate_h.in dexOf("-",pos1+1);
var strYear=cdate_h .substring(0,po s1);
var strMonth=cdate_ h.substring(pos 1+1,pos2);
var strDay=cdate_h. substring(pos2+ 1);
var userdate = strYear * 10000 + strMonth * 100 + strDay;
if (parseFloat(use rdate) < parseFloat(toda y))
{
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("completi on date");
return;
}
calDate = new Date();
var day = calDate.getDate ();
var month = calDate.getMont h() + 1;
var year = calDate.getFull Year();
var today = year * 10000 + month * 100 + day;
var pos1=cdate_h.in dexOf("-"); // date
format YYY-MM-DD
var pos2=cdate_h.in dexOf("-",pos1+1);
var strYear=cdate_h .substring(0,po s1);
var strMonth=cdate_ h.substring(pos 1+1,pos2);
var strDay=cdate_h. substring(pos2+ 1);
var userdate = strYear * 10000 + strMonth * 100 + strDay;
if (parseFloat(use rdate) < parseFloat(toda y))
{
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
Comment