[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 287
  • Last Modified:

Javascript "value is null or not an object"

Hi Experts:  I'm working with some JS I found on this forum (thankyou!)  This is probably a really stupid question, I've been looking at this way to long.  Can someone PLEASE solve the mystery.  "Value is null or not an object" when I try and submit this:

Thank you as usual

=============================================


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script type="text/javascript" language="JavaScript">
function countAge(object, birthDay){
     now = new Date();
     bD = birthDay.value.split('/');
     if(bD.length==3){
            born = new Date(bD[2], bD[1]*1-1, bD[0]);
          years = new Date(now.getTime() - born.getTime());
          base = new Date(0);
          document.all['AGE'].value = years.getFullYear()-base.getFullYear();
     }
}
function formatdate(datestr)
{
   var curdate = new Date();
   var curyear = (curdate.getYear()%100)+1980;  // to project 20 years forward and 80 years back (for birthdays, etc)

   datestr = datestr.split("-").join("/").split(".").join("/").split(" ").join("");
   if ( datestr == "" )
   {
      return(datestr);
   }

   // split the datestr into a 3 part array (mm/dd/yy)
   var mmddyy = datestr.split("/");
   if ( mmddyy.length != 3 )
   {
      return("NaN");
   }

   // add leading zeros to month and day
   if ( mmddyy[0].length == 1 )
   {
      mmddyy[0] = "0" + mmddyy[0];
   }

   if ( mmddyy[1].length == 1 )
   {
      mmddyy[1] = "0" + mmddyy[1];
   }

   // convert the year to a four digit year
   if ( mmddyy[2].length == 2 )
   {
      //mmddyy[2] = ( parseFloat(mmddyy[2]) > 49 ) ? '19'+mmddyy[2] : '20'+mmddyy[2];

      if ( Math.abs(curyear-parseFloat('19'+mmddyy[2])) <= Math.abs(curyear-parseFloat('20'+mmddyy[2])) )
      {
         mmddyy[2] = '19'+mmddyy[2];
      }
      else
      {
         mmddyy[2] = '20'+mmddyy[2];
      }
   }

   // rebuild the datestr from the formatted array, and check to see if it contains a valid date
   var tmpdate = new Date( datestr=mmddyy.join("/") );
   if ( tmpdate == "NaN" || tmpdate == "Invalid" )
   {
      return("NaN");
   }

   if ( parseFloat(mmddyy[0]) == tmpdate.getMonth()+1  &&  parseFloat(mmddyy[1]) == tmpdate.getDate()  &&  parseFloat(mmddyy[2]) > 1900  &&  parseFloat(mmddyy[2]) < 2100 )
   {
      return(datestr);
   }

   return("NaN");
}


function checkDate(datewidget)
{
   var datestr = formatdate(datewidget.value);

   if ( datestr == "NaN" )
   {
      datewidget.select();
      alert("Please enter a valid date for " + datewidget.name );
      datewidget.focus();
      return(false);
   }

   datewidget.value = datestr;

   return(true);
}


function validateForm(theform)
{
  var rc = checkDate(theform.Birth_Date);

  return(rc);
}
</script>
</head>

<body>
<cfform action="IAapproval_action.cfm" method="POST" onSubmit="return(validateForm(this));"
Name="theForm" enctype="multipart/form-data">
      <table>
         <tr>
      <td class="label"> Birth Date:</td>
      <td class="label2">
          <input value="" type="text" name="Birth_Date"   maxlength="10" size="8" onChange="validateForm(document.theForm);countAge(this.form, this);" required="yes"  />
         Age:
        <input value="" type="text" name="AGE" maxlength="3" style="background-color:F5F0E2" size="1" readonly="" />
             <input type="file" name="myFile1">
             <input type="submit" value="Continue" name="btnSubmit">
      </td>
    </tr>
      </table>
</cfform>
</body>
</html>
0
whaleyk
Asked:
whaleyk
1 Solution
 
smaccariCommented:
The point maybe is that you are using a CFFORM tag, that is NOT a HTML FORM tag (maybe a ColdFusion Tag).
So if you try this code on a simple HTML page, that will not work (theForm.Birth_Date will not reference to your input, but to an eventual attribute of the CFFORM tag).
Just change the tagname into FORM - dont forget the closing tag ;) - and all will be ok.
0
 
whaleykAuthor Commented:
ha ha... told ya it was stupid :-)  thx, you're right!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now