/t5/coldfusion-discussions/javascript-help-question/td-p/810830Mar 01, 2009
Mar 01, 2009
Copy link to clipboard
Copied
I have a cf form with <cfinput type=text
name="dateArrived" value="#dateformat(now(), 'mm/dd/yyyy')#"
onBlur="validateForm(initiateForm)">
When the form is first loaded, I display todays date but they
have the option of changing it. The only requirement is that the
date cannot be greater than today.
I call the following javascript function to try and check to
make sure the date entered is not greater than todays date (there
is other javascript code to check for valid date formats, requried
entry etc. :
function validateForm(initiateForm){
var returnStatus = true;
var today = new Date();
if (initiateForm.dateArrived.value > today)
(
alert("greater datea");
initiateForm.dateArrived.focus();
returnStatus(false);
}
But I keep getting a object error. I think I have everything
defined but obviously not. What am I doing wrong and do I need this
in its own function ? Seems simple enought but it will not work for
me.
I tried to modify my javascript code to check for the date,
and radio button and checkboxes included, and now nothing is being
called. When I submit, nothing is valideded and the form submits.
What did I do to butcher it ?
<Script language="JavaScript">
function validateForm()
{
var currentTime = new Date()
var month = currentTime.getMonth() + 1
var day = currentTime.getDate()
var year = currentTime.getFullYear()
var todaydate = month + "/" + day + "/" + year
if(document.initiateForm.dateArrived.value > todaysdate)
{
alert('Date Arrived cannot be greater than today.');
initiateForm.dateArrived.focus();
return(false);
}
if (document.initiateForm.dateArrived.value == "")
{
alert("Please enter the date arrived.");
document.initiateForm.dateArrived.focus();
returnStatus(false);
}
myOption = -1;
for (i=document.initiateForm.siteID.length-1; i > -1;
i--) {
if (document.initiateForm.siteID
.checked) {
myOption = i; i = -1;
}
}
if (myOption == -1) {
alert("Please select a site.");
returnStatus(false);
}
myOption = -1;
for (i=document.initiateForm.errorID.length-1; i > -1;
i--) {
if (document.initiateForm.errorID.checked) {
myOption = i; i = -1;
}
}
if (myOption == -1) {
alert("Please select at least one error description.");
returnStatus(false);
}
if (document.initiateForm.errorID["7"].checked &&
initiateForm.comments.value == "")
{
alert ("Comments are required.");
document.initiateForm.comments.focus();
returnStatus(false);
}
if (document.initiateForm.comments.value.length > 400)
{
alert ("Comments cannot be more than 400 characters.");
document.initiateForm.comments.focus();
returnStatus(false);
}
/t5/coldfusion-discussions/javascript-help-question/m-p/810832#M75205Mar 01, 2009
Mar 01, 2009
Copy link to clipboard
Copied
also, in addition to Dan's advice:
with this:
validateForm(initiateForm)
you are passing some js variable named initiateForm to your
validateForm() function, when i believe you want to pass the
name/id of
the form - if so enclose the form name in ' (single quotes).
better yet, pass the form object to your function:
validateForm(this.form)
/t5/coldfusion-discussions/javascript-help-question/m-p/810834#M75207Mar 02, 2009
Mar 02, 2009
Copy link to clipboard
Copied
LATEST
You made it almost impossible to debug by creating 1 big
function. It would be a lot easier to create one for each form
field you want to validate, and then a master one that simply calls
the others.
You seem to be missing some semi colons at the top
though.