Copy link to clipboard
Copied
I have this script but it only populate first 3 field of each fields in array. What am I doing wrong?
var fields = [
["Field A","Field B","Field C","Field D","Field E","Field F"],
["Text7","Text8","Text9","Text10"],
["f23","f24","f25","f26"]];
for(var j in fields){
if(event.value == "Test"){
this.getField(fields[0][j]).value = "Test1";
this.getField(fields[1][j]).value = "Test2";
this.getField(fields[2][j]).value = "Test3";}
else{
this.getField(fields[0][j]).value = "";
this.getField(fields[1][j]).value = "";
this.getField(fields[2][j]).value = "";}}
You can use one array instead like this:
var fields = ["Field A","Field B","Field C","Field D","Field E","Field F","Text7","Text8","Text9","Text10","f23","f24","f25","f26"];
for(var j=0; j<=13; j++){
if(event.value == "Test"){
this.getField(fields[j]).value = "Test1";
if(j>=6 && j<=9)
this.getField(fields[j]).value = "Test2";
if(j>=10 && j<=13)
this.getField(fields[j]).value = "Test3";}
else
this.getField(fields[j]).value = "";}
Copy link to clipboard
Copied
for(var j in fields){
This gives the values 0, 1, and 2 for the variable j.
Copy link to clipboard
Copied
Thanks Bernd, can you help me how to access arrays to populate all fields?
Copy link to clipboard
Copied
You use 3 arrays in one array. You can access the arrays with fields [j]
Copy link to clipboard
Copied
I'm sorry but i'm not sure what you mean, i'm not very familiar with javascript and i'm doing this for couple of hours now, i tried lots of combinations but nothing worked. Can you please explain to me i would really appreciate it?
Copy link to clipboard
Copied
You can access the elements like this:
for(var j in fields){
for (var i in fields[j]) {
... fields[j][i] ...
}
}
Copy link to clipboard
Copied
Can someone help i still didn't solve this?
Copy link to clipboard
Copied
You can use one array instead like this:
var fields = ["Field A","Field B","Field C","Field D","Field E","Field F","Text7","Text8","Text9","Text10","f23","f24","f25","f26"];
for(var j=0; j<=13; j++){
if(event.value == "Test"){
this.getField(fields[j]).value = "Test1";
if(j>=6 && j<=9)
this.getField(fields[j]).value = "Test2";
if(j>=10 && j<=13)
this.getField(fields[j]).value = "Test3";}
else
this.getField(fields[j]).value = "";}