Results 1 to 4 of 4

Thread: Does Javascript has the strlen()?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2000
    Posts
    303

    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

  2. #2
    AFAIK it's just like Java for this one:
    Code:
    if (myString.length() > 0)
    {
        alert("w00t!");
    }
    else
    {
        alert("bad! BAD!");
    }

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2000
    Posts
    303

    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

  4. #4
    Member Vincent Puglia's Avatar
    Join Date
    Feb 2002
    Location
    where the World once stood
    Posts
    36
    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
  •  



Click Here to Expand Forum to Full Width