Skip to main content
Inspiring
April 26, 2022
Question

Arrays

  • April 26, 2022
  • 4 replies
  • 2938 views

I've got a problem with arrays. I have a button that resets my form, but it doesn't do what I need for dropdown lists. Under "Actions" I added a piece Javascript to set the dropdown list to the "initial" state I need.

 

Now this code works:

 

this.getField("Student1").value="SSS"
this.getField("Student2").value="SSS"
this.getField("Student3").value="SSS"

 

But this doesn't work

 

v= new Array("Student1","Student2","Student3");
for (i=0; i<v.length; i++)
this.getField(v[i]).value="SSS"

 

What really confuses me is that it works for two of the three entries in the array.

 

Stumped and could use help.

 

Jack

This topic has been closed for replies.

4 replies

Bernd Alheit
Community Expert
Community Expert
April 26, 2022

It works for me:

JR Boulay
Community Expert
Community Expert
April 26, 2022

Resetting a field means returning it to its default value.

You should try this:

 

for (i=0; i<4; i++) {this.getField("Student" + i).value = this.getField("Student" + i).defaulValue;}

Acrobate du PDF, InDesigner et Photoshopographe
Inspiring
April 26, 2022

No, we are on the wrong track here. 

 

The problem isn't resetting a dropdown list, which works fine, the problem is that the code is trying to reset three dropdown lists and the loop ends prematurely. I put some alerts in there and the loop execution really ends prematurely.

Bernd Alheit
Community Expert
Community Expert
April 26, 2022

What happens when you use:

this.resetForm (v);

Inspiring
April 26, 2022

OK - Some progress, finally. Here is how I am using this. From the "Actions" for the button.

 

and it fails. but when I change this to run the Javascript before the reset form,

it works. Of course this causes other problems, but I can handle those. It still bothers me that the loop didn't work. There is something going on here that I don't understand.

 

try67
Community Expert
Community Expert
April 26, 2022

Sorry - Same results.


Are there any error messages in the JS Console? Can you share your actual file with us?

Bernd Alheit
Community Expert
Community Expert
April 26, 2022

Check the Javascript console for errors.

Inspiring
April 26, 2022

I admit that I'm not positive how to check the javascript console, but I have Acrobat set to pop up a window when there is a problem (i.e. undefined field), and nothing comes up. (See below)

 

 

Nesa Nurani
Community Expert
Community Expert
April 26, 2022

See if this will work:

for(var i=1; i<=3; i++)
this.getField("Student"+i).value = "SSS";