IndyB
06-13-2003, 02:06 PM
I've got a validation script that's giving me an error.
The error is: 'document.forms[...].elements' is null or not an object
Can anyone see what's going wrong here?
Here's the javascript function:
function docard_expiration(str,formname,fieldname)
{
reg = /\d+\W\d\d\d\d/;
newstr = str.replace(reg, "");
if (newstr != "")
{
document.forms[formname].elements[fieldname].value = "MM/YYYY";
}
else
{
reg = /(\d+)\W(\d\d\d\d)/;
month = str.replace(reg, "$1");
year = str.replace(reg, "$2");
checkmonth = Number(month) + 1;
tmpdate = new Date(checkmonth + "/1/" + year);
tmpdate = tmpdate - 86400000;
now = new Date();
timeDifference = now - tmpdate;
if (timeDifference < 0)
{
doformatdate(tmpdate);
document.forms[formname].elements[fieldname].value = formatdate;
}
else
{
if (document.forms[formname].elements[fieldname].value != "")
{
doformatdate(tmpdate);
alert("Expiration Date " + formatdate + " invalid.");
}
document.forms[formname].elements[fieldname].value = "MM/YYYY";
}
}
}
Here's the form field associated w/ this function:
<input type="Text" name="ExpDateCC" size="25" maxlength="17" onChange="docard_expiration('this.value', 'this.form.name', 'this.name')" onBlur="docard_expiration(this.value, this.form.name, this.name)">
The error is: 'document.forms[...].elements' is null or not an object
Can anyone see what's going wrong here?
Here's the javascript function:
function docard_expiration(str,formname,fieldname)
{
reg = /\d+\W\d\d\d\d/;
newstr = str.replace(reg, "");
if (newstr != "")
{
document.forms[formname].elements[fieldname].value = "MM/YYYY";
}
else
{
reg = /(\d+)\W(\d\d\d\d)/;
month = str.replace(reg, "$1");
year = str.replace(reg, "$2");
checkmonth = Number(month) + 1;
tmpdate = new Date(checkmonth + "/1/" + year);
tmpdate = tmpdate - 86400000;
now = new Date();
timeDifference = now - tmpdate;
if (timeDifference < 0)
{
doformatdate(tmpdate);
document.forms[formname].elements[fieldname].value = formatdate;
}
else
{
if (document.forms[formname].elements[fieldname].value != "")
{
doformatdate(tmpdate);
alert("Expiration Date " + formatdate + " invalid.");
}
document.forms[formname].elements[fieldname].value = "MM/YYYY";
}
}
}
Here's the form field associated w/ this function:
<input type="Text" name="ExpDateCC" size="25" maxlength="17" onChange="docard_expiration('this.value', 'this.form.name', 'this.name')" onBlur="docard_expiration(this.value, this.form.name, this.name)">