Copy link to clipboard
Copied
Why is it that when I click Acrobat's Clear Form option is clears all the fields populated by a document level JavaScript, and if I save the form the start up document level JavaScript no longer functions?
Or a link to the form or a sample form with the same problem.
You have only defined the function to be executed but not executed it.
You need to add a line like:
AtStartup();
to your script.
As noted if you were set the "defaultValue" for the fields then clearing the fields would remove any entry present and restore the default values.
Or you could write a custom JavaScript to clear the fields and then execute your startup script.
Copy link to clipboard
Copied
Can you post the script you're using?
Copy link to clipboard
Copied
The "reset a form" action that you can use as e.g. a button click handler will reset all fields to their default values. You can set the default value as part of the field properties. Resetting a form should not have any effect on document level functions. Are you getting any error message in the JavaScript console? What exactly is your document level script doing that is no longer working?
Copy link to clipboard
Copied
Not getting any errors in the JavaScript console. When I open the form the document level function runs ok. If I use Acrobat's built in Clear Form option it clears the document level function population of various fields on opening the form. If I then save the form the document level function no longer populates these fields. If I place the contents of document level function in a custom calculation script it runs ok and populates all the fields.
Copy link to clipboard
Copied
Once again, what exactly does your document level script do? Please post the whole script.
Copy link to clipboard
Copied
The function is named AStartUP
function AStartup()
{
this.getField("txtRowNo.0").value = "01" ;
this.getField("txtRowNo.1").value = "02" ;
this.getField("txtRowNo.2").value = "03" ;
this.getField("txtRowNo.3").value = "04" ;
this.getField("txtRowNo.4").value = "05" ;
this.getField("txtRowNo.5").value = "06" ;
this.getField("txtRowNo.6").value = "07" ;
this.getField("txtRowNo.7").value = "08" ;
this.getField("txtRowNo.8").value = "09" ;
this.getField("txtRowNo.9").value = "10" ;
this.getField("txtRowNo.10").value = "11" ;
this.getField("txtRowNo.11").value = "12" ;
this.getField("txtRowNo.12").value = "13" ;
this.getField("txtRowNo.13").value = "14" ;
this.getField("txtRowNo.14").value = "15" ;
this.getField("txtRowNo.15").value = "16" ;
this.getField("txtRowNo.16").value = "17" ;
this.getField("txtRowNo.17").value = "18" ;
this.getField("txtRowNo.18").value = "19" ;
this.getField("txtRowNo.19").value = "20" ;
)
Copy link to clipboard
Copied
In addition to the need to actually call the file, there is also a syntax error in your script: A function definition is wrapped in { and } - you start with a {, but end with a ) on the last line. Change the last line to } (and call your function), and you should be all set. To call the function, just add the call to your function as the last line of your document level script.
Copy link to clipboard
Copied
Or a link to the form or a sample form with the same problem.
You have only defined the function to be executed but not executed it.
You need to add a line like:
AtStartup();
to your script.
As noted if you were set the "defaultValue" for the fields then clearing the fields would remove any entry present and restore the default values.
Or you could write a custom JavaScript to clear the fields and then execute your startup script.
Copy link to clipboard
Copied
Testing the form I notice if the fields that the document level populates are blank when saved, the form takes some time to open. But if the form is saved with the fields populated the time to open is noticeably quicker. Is there a better method for populating text fields with values?
Copy link to clipboard
Copied
That can happen if Acrobat isn't opened, or if it is, if the JavaScript engine hasn't been started. So the delay is the JavaScript engine starting up. If you close the form and leave Acrobat running, if you reload the form you probably won't see a delay.
Copy link to clipboard
Copied
I would expect there is a lot more going on than just this one script that is slowing down the form's opening. I would consolidate as many of the scripts as possible and possibly changing where some of the scripts run. Not all fields need to updated the calculation script. For example check boxes and radio button could update other field by use of the mouse up action in some instances.
For the default value of the form fields in question I would have use the field's' properties to set the Default Value on the Options tab.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now