views:

23

answers:

2

Hi Guys,

I am trying to use Prototype and startsWith but I want to check a number of values and little confused how to do this.

Basically have this code:

if(Category.startsWith("[Test1] " || "Test " || "Test2 ")) { some stuff }

It doesn't appear to be working and just wondering what I am doing wrong ?

+2  A: 

You need to do them individually:

if(Category.startsWith("[Test1] ")
   || Category.startsWith("Test ")
   || Category.startsWith("Test2 ")) {
    // some stuff
}

In JavaScript, the expression

"[Test1] " || "Test " || "Test 2 "

...evaluates to "[Test1] ", because || returns the first "truthy" operand.

T.J. Crowder
thanks ill give this a whirl
John
super worked :) thanks a lot. spender responded first but thanks so much for your answer :)
John
A: 
if(Category.startsWith("[Test1] ")
    ||Category.startsWith("Test ")
    ||Category.startsWith("Test2 ")) 
{ 
    //some stuff
}
spender
oh great ok - ill give this a shot ))
John
super worked :) thanks a lot.
John