Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

if statement with wildcard

Avatar

Avatar
Validate 10
Level 2
eugzl
Level 2

Likes

5 likes

Total Posts

171 posts

Correct Reply

5 solutions
Top badges earned
Validate 10
Validate 1
Ignite 5
Ignite 3
Ignite 1
View profile

Avatar
Validate 10
Level 2
eugzl
Level 2

Likes

5 likes

Total Posts

171 posts

Correct Reply

5 solutions
Top badges earned
Validate 10
Validate 1
Ignite 5
Ignite 3
Ignite 1
View profile
eugzl
Level 2

03-03-2018

Hi All.

I have huge drop down list with some items finish on same content. For instance,

AAA - 4 weeks

BBB - 2 weeks

CCC - 3 weeks

DDD - 4 weeks

EEE - 2 weeks

FFF - 4 weeks

GGG - 2 weeks

and so on.

is it possible specify wildcard in IF statement? What I mean.

if (dropdown1.rawValue == %4 weeks) {

     Textbox1.presence  = "invisible";

}

else if (dropdown1.rawValue == %3 weeks) {

     Textbox2.presence  = "invisible";

}

else if (dropdown1.rawValue == %2 weeks) {

     Textbox3.presence  = "invisible";

}

Thanks.

Accepted Solutions (0)

Answers (2)

Answers (2)

Avatar

Avatar
Validate 1
Level 4
mouslander
Level 4

Likes

23 likes

Total Posts

298 posts

Correct Reply

27 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 10
Boost 1
View profile

Avatar
Validate 1
Level 4
mouslander
Level 4

Likes

23 likes

Total Posts

298 posts

Correct Reply

27 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 10
Boost 1
View profile
mouslander
Level 4

04-03-2018

You can use the string match (see below).

var str = "4 Weeks";

var res = str.match(/4 weeks/g);

This would make it more complex. Another way would be to use the || opperator

if(this.rawValue == "AAA - 4 weeks" || this.rawValue == "DDD - 4 weeks"){

do something...

Avatar

Avatar
Validate 1
Level 4
MinusZero
Level 4

Likes

30 likes

Total Posts

326 posts

Correct Reply

54 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 25
Boost 10
View profile

Avatar
Validate 1
Level 4
MinusZero
Level 4

Likes

30 likes

Total Posts

326 posts

Correct Reply

54 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 25
Boost 10
View profile
MinusZero
Level 4

04-03-2018

Hi,

I dont know about using wild cards, but what you have shown as an example would work well using a switch.

switch(dropdown1.rawValue)

{

case "1 Week":

     Textbox1.presence = "invisible";

     break;

case "2 Weeks":

     Textbox2.presence = "invisible";

     break;

default:

     //you can enter a command if you wish to execute if none of the other conditions are met. This is kind of like an 'else'

     break;

}

You need to have default at the end. The switch works by looking at the value in the brackets and uses the value to find the 'case' and execute the commands. It is basically a much tidier if statement.