Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Javascript help/question

New Here ,
Mar 01, 2009 Mar 01, 2009
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.
382
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 01, 2009 Mar 01, 2009
Whatever is in the form will be a string. You have to convert it to a date before comparing it to another date.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 02, 2009 Mar 02, 2009
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);
}

return(true);
}

</Script>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 01, 2009 Mar 01, 2009
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)

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 02, 2009 Mar 02, 2009
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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources