Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

if statement with wildcard

Avatar

Level 5

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.

2 Replies

Avatar

Level 7

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.

Avatar

Level 7

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...