Problem in returning String length - Javascript

On my form I have a textfield named CndnInsDOB...I'm trying to write a routine to force the applicant to enter the birthdate as 8 continuous digits, no spaces, commas or slashes...if they don't, an alert window opens...first alert is here just to see if was reading the variable dob_length correctly...it's NOTreading at all...

tried the folowing:

<script LANGUAGE="JavaScript" type="text/javascript">
function DOBcheck() {
var dob_length=document.forms[0].CndnInsDOB.value.length;
   alert("length is "  + dob_length + );
}

if (dob_length = 8) {
return true;
   }
   else {
   alert("Date of Birth: INCORRECT FORMAT" & chr (13) & chr 13 &  _
   "Date Of Birth should be entered in the following format:" & chr (13) & chr 13 &  _
   "                         DDMMYYYY                       " & chr (13) & chr 13 &  _
   "        DO NOT include any space, - or / character(s)   ");
   document.forms[0].CndnInsDOB.focus
   document.forms[0].CndnInsDOB.select
return false;
   }
</SCRIPT>
ronaldjAsked:
Who is Participating?
 
lilian-arnaudConnect With a Mentor Commented:


replace :

if (dob_length = 8) {

by :

if (dob_length == 8) {
0
 
sysiphusCommented:
How are you calling the proc?
0
 
ronaldjAuthor Commented:
from an OnFocus event found in the next field...

seems to be the way I'm referencing the variable CndnInsDOB...

<input type="text" name="CndnInsDOB" value="$CndnInsDOB$"  onkeypress="return handleEnter(this, event)" onFocus="highlight(event)" size="26" style="font-family: Arial; font-size: 10pt">

I have used the convention

   document.forms[0].VariableName.value

in other JS scripts on this form, no problem...
0
All Courses

From novice to tech pro — start learning today.