Skip to main content
first.officer
Inspiring
October 10, 2020
Answered

JavaScript to reset fields on specific page within document

  • October 10, 2020
  • 3 replies
  • 3385 views

Hi,

 

Am wondering if there is a script that would allow for a single page of field entries a user has made, to be cleared in entirety, likely using the function;

 

this.resetForm() 

 

Ideally looking to achieve this with script that doesn't require naming each field individually (lots of fields!) like the example shown below, but perhaps just allows the reset of the page itself?.

 

this.resetForm(["Field1", "Field2", "Field5"]);

 

The standard reset form function in DC Pro is somewhat annoying in as much as if you then add more fields later on after setting which specific fields you have ticked earlier on in making the form, it seems to add those new fields as well, which is frustrating as quite often you might want to adapt and create more fields etc. later on.

This topic has been closed for replies.
Correct answer Nesa Nurani

You can find the code you need in this link:

https://answers.acrobatusers.com/Reset-one-page-of-multi-page-form-q51725.aspx 

 

3 replies

goldilocks22
Participating Frequently
October 20, 2022

Hello - Looking for help with this also, but the link provided give me the 404 web error. Can you post a corrected link?

Thom Parker
Community Expert
Community Expert
October 20, 2022

This code will reset all fields on the currently displayed page.  It includes field that appear on both the target page and another page. This code will only operate in Acrobat DC, not on previous versions of Acrobat.

 

 

 

var nResetPage = this.pageNum;
var oFld, strFldName, aPgs, aFldNames=[];
for(var i=0;i<this.numFields;i++)
{
    strFldName = this.getNthFieldName(i);
    oFld = this.getField(strFldName);
    aPgs = (typeof(oFld.page) == "number")?[oFld.page]:oFld.page;
    if(aPgs.some(a=>a==nResetPage)) aFldNames.push(strFldName);
}
this.resetForm(aFldNames);

 

 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
goldilocks22
Participating Frequently
October 20, 2022

Thanks so much Thom!  This is a doc level script, correct?

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
October 10, 2020
first.officer
Inspiring
October 10, 2020

Hi NesaNurani,

 

Yes, did see that - but couldn't get it to work ;-(

first.officer
Inspiring
October 10, 2020

Durr....my bad....i'd added a typo character when copying - works like a charm - thanks!

Inspiring
October 10, 2020

Do you want button on each page that will reset that page or you want button on first page that can reset any page?

first.officer
Inspiring
October 10, 2020

Hi Asim123,

 

Button on each page that will reset that page.....;-)