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
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Script for changing objects presence based on amount range

Eric_Rosenfeld
Level 2
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
_Bruce_Robertson
Correct answer by
Level 10
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
_Bruce_Robertson
Correct answer by
Level 10
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

Eric_Rosenfeld
Level 2
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

_Bruce_Robertson
Level 10
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