Copy link to clipboard
Copied
Hello,
I'm using a document level array with 16 elements to hold values, each of these values corresponds to a text field.
What I am wanting to do is create 2 arrays, one storing the values and one storing the field names themselves in the correct order.
eg element 0 of both arrays correspond to the text field and it's stored value.
I want to know if I can loop through both of these arrays and set the values in one sweep rather than writing;
var txt01 = this.getField("Text1");
var txt02 = this.getField("Text2");
//... Etc
txt01.value = arrTextVal[0];
txt02.value = arrTextVal[1];
//... Etc
Could I write something more along the lines of;
for (var i in arrTextVal && arrTextName) {
arrTextName.value = arrTextVal;
}
I realise this may be completely wrong but I'm trying to give a clear example if what I'm trying to achieve.
Any help is much appreciated.
Thank you in advance.
Assuming the two arrays have the same length and the items in them are in the same order you can simply do this:
for (var i=0; i<arrTextVal.length; i++) {
arrTextName.value = arrTextVal;
}
Copy link to clipboard
Copied
Assuming the two arrays have the same length and the items in them are in the same order you can simply do this:
for (var i=0; i<arrTextVal.length; i++) {
arrTextName.value = arrTextVal;
}
Copy link to clipboard
Copied
I've got something a little more involved in mind next but I'm not sure if it's even possible.
I want to take that array structure and create it from scratch with another JavaScript, however there is a catch, I would need to do this many times and each Array needs a unique name, am I able to increment an array's name on creation?
The values inside the array would be the same, 16 values and 16 text field names, however the array does need to be unique.
So for example something along the lines of;
var i = 0; i++;
var newArrayVal = new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
This is because as with the majority of the things I am doing this system needs to work with templates and spawned pages and so each newly spawned page needs it's own unique array
Would this even be possible?
Copy link to clipboard
Copied
You can create an array of arrays. You can't change the name of a variable dynamically, though.
Copy link to clipboard
Copied
Thank you for the quick reply, I'll have a look into creating an array of arrays.
Copy link to clipboard
Copied
Use something like this:
for (var i=0; i<arrTextVal.length; i++) {
this.getField(arrTextName).value = arrTextVal;
}
Copy link to clipboard
Copied
Thank you both for your helpful answers!
Copy link to clipboard
Copied
You might also want to look using hierarchical field names and the "getArray()" field method.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now