Skip to main content
Henry.Ong
Inspiring
July 19, 2022
Answered

How to create a RESET button for selected fields with a confirmation message?

  • July 19, 2022
  • 3 replies
  • 4735 views

Hello!

Need help. I have created a fillable PDF with 2 pages.

What I want is to have a Reset button for each page that only clears PDF fields on that page with a confirmation if they wish to continue before the actual clearing of the PDF fields.

Example:

Let us assume that on Page 1, I have the following PDF fields:

F01001

F02002

F02003

F03005

And on Page 2, I have the following PDF fields:

G03004

G03007

G06009

G07001

The Reset button on Page 1 should clear only those PDF fields on Page 1. The same with the Reset button on Page 2.

I wish that before actually clearing these PDF fields (either on Page 1 or Page 2), it would first ask the question, “Do you wish to continue (Y/N)?” Only if the answer is Y will the clearing of PDF fields on that page will proceed.

Thank you in advance.

Correct answer Nesa Nurani

Sorry, I thought you wanted to clear fields on specific pages.

Use this in a button:

 

 

var resetTheseFields = ["F01002","F01005"];
var alert = app.alert("Are you sure you wish to delete fields on this page?",0,2);
if(alert == 4)
this.resetForm(resetTheseFields);

 

 

 

 

3 replies

JR Boulay
Community Expert
Community Expert
July 19, 2022

1.

 

Acrobate du PDF, InDesigner et Photoshopographe
JR Boulay
Community Expert
Community Expert
July 19, 2022

2.

Use this script:

 

var alert = app.alert("Are you sure you wish to delete fields on this page?",0,2);
if(alert == 4){
this.resetForm("F02002");
this.resetForm("F02005");
}

Acrobate du PDF, InDesigner et Photoshopographe
Henry.Ong
Henry.OngAuthor
Inspiring
July 20, 2022

Thank you, JR for the help.

Nesa Nurani
Community Expert
Community Expert
July 19, 2022

Use this as 'Document level script':

function resetFieldsOnPage(doc, p){
var fields = [];
for (var i=0; i<doc.numFields; i++) {
var f = doc.getField(doc.getNthFieldName(i));
if(f==null) continue;
if(fields.indexOf(f.name)==-1 && ((typeof f.page=="number" && f.page==p) || (typeof f.page=="object" && f.page.indexOf(p)!=-1)))
fields.push(f.name);}
return fields;}

Then use this in a 'reset' button as 'Mouse UP' event:

var alert = app.alert("Are you sure you wish to delete fields on this page?",0,2);
if(alert == 4){
var cFields = resetFieldsOnPage(this, 0);
this.resetForm(cFields);}

(this, 0) will reset fields on first page since first page is numbered 0, on second page change 0 to 1, on 3rd change to 2...etc.

Henry.Ong
Henry.OngAuthor
Inspiring
July 19, 2022

Hi Nesa,

 

Thank you for replying to my concern.

 

Two questions:

 

1) Where can I define the Document level script?

 

2) What if I only want selected PDF fields on a certain page to be cleared and not all the PDF fields?

In the samples I have provided, I only want to clear F02002 and F02005. How can can I do this?

 

Thanks again.

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
July 19, 2022

Sorry, I thought you wanted to clear fields on specific pages.

Use this in a button:

 

 

var resetTheseFields = ["F01002","F01005"];
var alert = app.alert("Are you sure you wish to delete fields on this page?",0,2);
if(alert == 4)
this.resetForm(resetTheseFields);