I have been struggling to solve this problem for a few days now, and I'm slowly losing my mind.
- I am in Adobe Acrobat 10.
- I have a group of button fields called: btn0, btn1, btn2, etc.
- I have a group of text fields called: txt0, txt1, txt2, etc.
- I have a script that takes the value of txt0 and makes it the caption for btn0, and so on.
- I have a script that sets the MouseUp action of btn0 to setFocus to txt0, and so on.
- These scripts work fine.
- I have a script that takes the values of all the txt fields and puts them in an array, and sorts it.
- I have a script that takes the array[0] item and makes it the caption for btn0, and so on (alphabetizing my list of buttons).
- Those scripts work fine.
- I am trying to compare the value of the array[0] item to each of the txt fields to find the match, and then set the MouseUp action of btn0 to setFocus to the matching txt field, and so on (so my alphabetized list points to the correct locations).
- This is where I'm at a loss.
Here is what I have:
//specified the txt fields
var txt0 = this.getField("Z name");
var txt1 = this.getField("A name");
//etc.
//put their values into an array called rxArray
var rxArray = [txt0.value, txt1.value]; //etc.
//sorted the array
rxArray.sort();
//set the captions equal to the sorted array items
for (var i = 0; i < 5; i++) {
var b = ("btn" + i);
this.getField(b).buttonSetCaption(rxArray[i]); //works fine; alphabetizes the list of buttons
//below is what goes wrong
for(var x = 0; x < 5; x++) {
var r = ("txt" + x);
if(rxArray[i] == r.value){
var s = (r + ".setFocus();");
this.getField(b).setAction("MouseUp", s);
}
}
}
//end
Here is what I know:
The alphabetizing and labeling works fine, but the buttons' MouseUp scripts don't work at all. Nothing happens.
If I change the following piece of the above script:
if(rxArray[i] == r.value){
var s = (r + ".setFocus();");
this.getField(b).setAction("MouseUp", s);
To this:
if(rxArray[i] == txt1.value){
var s = (r + ".setFocus();");
this.getField(b).setAction("MouseUp", s);
Because rxArray[0] does equal the value of txt1 ("A name"), then the MouseUp script for btn0 gets set to:
txt4.setFocus();
So I know that, each time the nested loop runs, the if statement is true, and the setFocus script updates. Until the end of the loop, leaving the setFocus as the last item run. So why doesn't my script work? It should only update the setFocus script IF the array item matches the txt field, and should set it to THAT txt field.
Please please help. I know I'm missing something simple in there somewhere.