Expand my Community achievements bar.

Enhance your AEM Assets & Boost Your Development: [AEM Gems | June 19, 2024] Improving the Developer Experience with New APIs and Events

if statement with wildcard


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";



2 Replies


Level 7


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



case "1 Week":

     Textbox1.presence = "invisible";


case "2 Weeks":

     Textbox2.presence = "invisible";



     //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'



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.


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