Problem in returning String length - Javascript

Posted on 2004-11-12
Last Modified: 2010-04-17
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'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)   ");
return false;
Question by:ronaldj

    Expert Comment

    How are you calling the proc?

    Author Comment

    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


    in other JS scripts on this form, no problem...
    LVL 3

    Accepted Solution


    replace :

    if (dob_length = 8) {

    by :

    if (dob_length == 8) {

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    A short article about problems I had with the new location API and permissions in Marshmallow
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now