--------------------------------------------------------------------------------
I am using a javascript form validator, which works in IE, although it complains that the "frm = document.poForm;" line is not an object. But in Netscape anytime a submit button is clicked, the alert msg box pops up and beeps, whether or no the field is correct.
I include here the javascript from the HTML page and the relevant part of the validate.js file
***********************************
Validate.js::
// Check if Field contains a valid date of the form dd/mm/yy
function IsValidDate(Field)
{
if (!ContainsSomething(Field))
{
return false;
}
var indate=Field.value;
var sdate = indate.split("/")
var chkDate = new Date(Date.parse(indate))
var cmpDate = (chkDate.getMonth()+1)+
"/"+(chkDate.getDate())+
"/"+(chkDate.getYear())
var indate2 = (Math.abs(sdate[0]))+"/"+(
Math.abs(sdate[1]))+
"/"+(Math.abs(sdate[2]))
if (indate2 != cmpDate || cmpDate == "NaN/NaN/NaN")
{
return false
}
else
{
return true;
}
}
The HTML script
*********************************************
<script language="JavaScript"><!--
// Generator: Validator 98
function CheckForm()
{
//msg = ""; // **DEBUG ONLY**
frm = form.document.poForm;
for ( y=1; y <= frm.itemCount.value; ++y )
{
fld = frm.elements["drawdeldate"+y];
//msg += ( fld.name + ": " + fld.value + "\n" ); // **DEBUG**
//if ( fld.value == "" ) // CHANGE TO CALL IsValidDate !!
if (!IsValidDate(fld))
{
alert ("Please insert a Drawing Delivery date in the format mm/dd/yyyy for item " + y);
fld.focus( );
return false;
}
fld = frm.elements["equipdeldate"+y];
//msg += ( fld.name + ": " + fld.value + "\n" ); // **DEBUG**
//if ( fld.value == "" ) // CHANGE TO CALL IsValidDate !!
if (!IsValidDate(fld))
{
alert ("Please insert an Equipment Delivery date in the format mm/dd/yyyy for item " + y);
fld.focus( );
return false;
}
}
//alert(msg); // **DEBUG**
return true;
}
// ************************* END OF SCRIPT *****************
I am no expert when it comes to JavaScript but has it got something to do with this:
frm = form.document.poForm;
Having to be frm = document.form['poForm'];
That is if the form is called poForm which I am assuming since you didnt actually enter the form html or give the form name you want the script to validate.
Bookmarks