|
-
Jan 31st, 2002, 08:30 PM
#1
Thread Starter
Hyperactive Member
Does Javascript has the strlen()?
Hi all,
I have an onChange then call a function, but inside of my
function I would like to know whether the variable is blank.
Here is the sample code:
OnChange="assignValue(2,this.options[this.selectedIndex].text)"
...
function assignValue(opt, myString)
{
//HOW do I check to see if myString is blank and/or has
// 0 length?
}
Thanks in advance for the help.
Jay
-
Jan 31st, 2002, 09:25 PM
#2
Member
AFAIK it's just like Java for this one:
Code:
if (myString.length() > 0)
{
alert("w00t!");
}
else
{
alert("bad! BAD!");
}
-
Feb 1st, 2002, 11:31 AM
#3
Thread Starter
Hyperactive Member
Thanks, Filburt1 -- read my msg
Hi Filburt1,
You were correct, but it would not work with the
myString.length(). However, it works fine with
if (myString.length > 0)
Thanks for the help.
Jay
-
Feb 3rd, 2002, 12:23 PM
#4
Member
Hi,
'length' in javascript is not a method/function, but a property of every element.
You can also check like this:
if (myString == "") alert('it is blank')
or if you are into functions, define one:
function isEmpty(strVar)
{
return (strVar == "")
}
or:
function strlen(strVar)
{
return(strVar.length)
}
alert((strlen('') == 0))
alert(strlen(''))
alert(strlen('a'))
Vinny
Last edited by Vincent Puglia; Feb 3rd, 2002 at 12:27 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|