Incrementing the Counter dynamically in Adobe forms using Java script.
We might come across certain situations where we need to increment the numeric counter
We have a table of contents in order
1 – A
2 – B
3 – C
4 – D
5 – E
Here the counter is starting from 1 to 5 depending on the respective alphabets (In real world dynamic Values).
If we have a requirement to display only:
Then the corresponding counter should be as :
1 – A
2 – C
3 – E
But not as
1 – A
3 – C
5 – E.
In order to deal with these kinds of situations, we can write form calc or java script at the script editor.
In the below screen shot you have the increment text field in the Hierarchy node and the out on the design view.
In the Script editor we have assigned value this.rawValue = 0.
And there is not dynamic binding for the text field Increment.
In order to obtain the increment counter dynamically for the first column of the table. We need to proceed in the following way:
Create a text field and assign its value to 0.
Event — Initialize event.
Language — Java Script.
Run At — Client.
this.rawValue = 0;
The above code initializes the value of the Increment field to “Zero”.
After initializing the value to zero, now we have to increment the counter dynamically depending on the display of the column two.
To obtain the above scenario, we need to writ the following Java script.
a = this.parent.parent.parent.parent.parent.INCREMENT.rawValue;
b = ++a;
- this.rawValue = b ;
- this.parent.parent.parent.parent.parent.INCREMENT.rawValue = b;
- Declaring a local variable “a’.
- Calling the Increment value and assigning that value to the local variable ‘a’.
We need to refer those many ‘parents’.
- As increment is assigned to zero.
- At first instance the value of a = 0.
- The value of ‘b’ becomes 1.
- And later this ‘b’ value is assigned to the column 1 value. And this B value is assigned back to the Increment for using down the form.
- As the rows of the table increase the counter value increases as the local variable always refer to the INCREMENT value and this increment value is always being modified with updated incremented value.
- Hence the values of the column 2 ,3,4,5 etc display according to the incremented values.