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.

How to compare global variable value to TextField value

Avatar

Level 5

Hi All.

I create global variable Names with values: John, Bill.

Now I would like to compare global variable to entered value in TextField. For instance:

if (TextField1.rawValue == Global.John) {

TextField2.presence = "hidden";

}

How to do that?

Thanks.

4 Replies

Avatar

Level 7

Hi,

It should work as you have written as long as your script object is named Global and your variable is named John.

You would put the if statement into TextField1's Exit event. When the field is exited, if there is a match with the variable, TextField2 will be hidden.

1461733_pastedImage_0.png

1461755_pastedImage_1.png

In my example, if i put 1 in the textfield and then exit it, textfield2 is hidden as textfield1 equals the Global.John variable contents.

Before Exiting

1461756_pastedImage_2.png

After Exiting

1461757_pastedImage_4.png

Avatar

Level 5

Hi MinusZero. Thanks for replay.

In your example, if I understood correct, you insert Script Object named Global. But I asked about global variable. In my form I created global variable NAMES with values John,Bill. That is like global array.

global_var.png

Please, let me know how can i declare a array that is GLOBAL. If to say Names[0]. Is that John?

Thanks.

Avatar

Level 7

I create global variables like this.

Right click the Form in the Hierarchy View and Select Insert Script Object

1461915_pastedImage_0.png

Rename the script object Global

1461916_pastedImage_1.png

While selected, open the code view and write your variables

1461951_pastedImage_4.png

The variables are referenced by Global.John etc

You can also change the global variable by referencing it in this way.

Avatar

Level 7

Here is a simple tutorial

I have a script object with the John variable with a value of 1

1461954_pastedImage_5.png

I have a numeric field which in it its initialise event it has

form1.#subform[0].NumericField1::initialize - (JavaScript, client)

this.rawValue = Global.John; //display the variable when the form starts

I have a button which adds 1 to the global variable John when clicked.

form1.#subform[0].Button1::click - (JavaScript, client)

Global.John = Global.John + 1; //add 1 to the variable everytime it is clicked.

I have another numericField and i have a second button which when clicked sends the new John variable value to the numericField.

form1.#subform[0].Button2::click - (JavaScript, client)

NumericField2.rawValue = Global.John;

When form is started, Global.John is displayed in the NumericField

1461952_pastedImage_1.png

Click +1 button 3 times (variable becomes 4)

Click New John Value Button. The new variable value is displayed in the 2nd numeric field.

1461953_pastedImage_2.png

I hope this helps