True.  The efficiency freak in me doesn't like looping over every character (as your function does), though on the client, that may not be a significant issue.

--
Billy Cravens
HR Web Development, Sabre
[EMAIL PROTECTED]

Robert Hinojosa wrote:

 I usually have a strip whitespace function also.  Your's is definately more elegant, but someone that doesn't know RegEx's might have trouble with it.function trimString(sString){
   if (sString.charAt(0)==" ")
   {sString=sString.substring(1,sString.length);return trimString(sString);}
   else if (sString.charAt(sString.length-1)==" ")
        {sString=sString.substring(0,sString.length-1);return trimString(sString);}
   else
        return sString;
}
-----Original Message-----
From: Billy Cravens [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, February 28, 2001 10:12 AM
To: [EMAIL PROTECTED]
Subject: Re: Error message with JavaScript
 
Robert,

It doesn't do *exactly* the same thing.  If you just check length, then it will not catch someone who types in spaces (with no characters)

--
Billy Cravens
HR Web Development, Sabre
[EMAIL PROTECTED]

Robert Hinojosa wrote:

 

Henry,
This does the same thing.

function checkForm()
{
  frm = document.member_add_form;
        if(!frm.FName.value.length)  // this line creates a problem
{
     alert("You left first name blank.") ;
     return false;
}

Robert
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, February 28, 2001 8:41 AM
To: [EMAIL PROTECTED]
Subject: Error message with JavaScript

Hi guys,

When the two functions below are called I receive an error message:
JavaScript Error:
http://statweb/henry/test/member_add_form.cfm, line 120:
document.member_add_form.FName has no properties.
What is wrong? The Fname field is in a table on the member_add_form.cfm

<script language="JavaScript">
function IsBlank(str)
{
var intBlank = str.search(/[^\s+]/);
if (intBlank)
{
noChars=str.search(/[^\S{str.length}]/);
}
else
{
noChars = 1;
}
if (noChars < 1)
{
return true;
}
 else
{
return false;
}
}

function checkForm()
{
     if
     (IsBlank(document.member_add_form.FName.value))  // this line creates
a problem
{
     alert("You left one or more fields blank.") ;
     return false;
}
}
</script>

Thanks in advance,

Henry

-------------------------------------------------------------------------
This email server is running an evaluation copy of the MailShield anti-
spam software. Please contact your email administrator if you have any
questions about this message. MailShield product info: www.mailshield.com

-----------------------------------------------
To post, send email to [EMAIL PROTECTED]
To subscribe / unsubscribe: http://www.dfwcfug.org


 

  ------------------------------------------------------------------------- This email server is running an evaluation copy of the MailShield anti- spam software. Please contact your email administrator if you have any questions about this message. MailShield product info: www.mailshield.com


 
 
  ------------------------------------------------------------------------- This email server is running an evaluation copy of the MailShield anti- spam software. Please contact your email administrator if you have any questions about this message. MailShield product info: www.mailshield.com

Reply via email to