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

I'm afraid it did even less. It acted exactly the same way as using the default "reset form".

 

The problem here is that there appears to be no clear definition of "resetting a dropdown list". One would assume it means setting it back and the initial default values, but apparently it is not.

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";