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

Script for changing objects presence based on amount range

Avatar

Level 2

Hello,

Is there a way to change an objects presence (either a field or a subhead) based on the entered amount range in a numeric field? 

For example:

-The numeric field amount entered is a range between 1 and 49,999, then "Signature Subhead 1" appears.

-The numeric field amount entered is a range between 50,000 and 250,000, then "Signature Subhead 2" appears.

Etc.

Any advice for this script would be appreciated.

Thanks!

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

Try something like this JavaScript in the exit event of your numeric field (you will probably have to change the name of your form objects, SignatureSubhead1 and SignatureSubhead2)


switch (true)


{


case this.rawValue >= 1 && this.rawValue <= 49999:


  SignatureSubhead1.presence = "visible";


  SignatureSubhead2.presence = "hidden";


  break;


case this.rawValue >= 50000 && this.rawValue <= 250000:


  SignatureSubhead1.presence = "hidden";


  SignatureSubhead2.presence = "visible";


  break;


default:


  SignatureSubhead1.presence = "hidden";


  SignatureSubhead2.presence = "hidden";


}



Regards

Bruce

View solution in original post

3 Replies

Avatar

Correct answer by
Level 10

Hi,

Try something like this JavaScript in the exit event of your numeric field (you will probably have to change the name of your form objects, SignatureSubhead1 and SignatureSubhead2)


switch (true)


{


case this.rawValue >= 1 && this.rawValue <= 49999:


  SignatureSubhead1.presence = "visible";


  SignatureSubhead2.presence = "hidden";


  break;


case this.rawValue >= 50000 && this.rawValue <= 250000:


  SignatureSubhead1.presence = "hidden";


  SignatureSubhead2.presence = "visible";


  break;


default:


  SignatureSubhead1.presence = "hidden";


  SignatureSubhead2.presence = "hidden";


}



Regards

Bruce

Avatar

Level 2

Hi Bruce,

Your solution worked perfectly.  If I was to expand the ranges (let's say to three ranges), would I just have to add another "case this" logic section such as this?

switch (true)  

{  

case this.rawValue >= 1 && this.rawValue <= 49999:  

  SignatureSubhead1.presence = "visible";  

  SignatureSubhead2.presence = "hidden";

  SignatureSubhead3.presence = "hidden"

  break;  

case this.rawValue >= 50000 && this.rawValue <= 249999:  

  SignatureSubhead1.presence = "hidden";  

  SignatureSubhead2.presence = "visible";

  SignatureSubhead3.presence = "hidden";    

  break;

case this.rawValue >= 250000 && this.rawValue <= 500000:    

  SignatureSubhead1.presence = "hidden";  

  SignatureSubhead2.presence = "hidden";

  SignatureSubhead3.presence = "visible";    

  break;  

default:  

  SignatureSubhead1.presence = "hidden";  

  SignatureSubhead2.presence = "hidden";

  SignatureSubhead3.presence = "hidden";   

}

Appreciated,

Eric

Avatar

Level 10

Hi,

Exactly, this is the advantage of using a switch statement as opposed to series of if statements, this way should be easier to extend.

Good luck

Bruce