Skip to main content
Known Participant
September 18, 2021
Answered

Clear button should have YES / NO

  • September 18, 2021
  • 2 replies
  • 6536 views

-------------------------------------------------------------------------------------------------------------------------------

Clear Form (Mouse Up)

 

When you click the “Clear Form” button a Message box should popup and say:

 

“STOP!

DO NOT clear this form until you saved it under Suspect name; LAST, First & Date.

Do you want to clear this form?”

                                                                                               YES     NO

 

When you click “YES” the form should be cleared and the Message box should close.

When you click “NO” the Message box should close and the form will NOT be cleared

 

Ia there javascript available that can do this? I gave up searching.

Any help would be greatly appreciated by 4,000 cops

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

Nesa,

I put this together from your script and added 25 field names. When I tested it I got a syntax error. I don't know what I did wrong because it looks like yours and yours works great. Any idea what I need to do to fix it?

Thank you again,

Lance

var fields = [];
for (var i=0; i<this.numFields; i++) {
var f = this.getField(this.getNthFieldName(i));
fields.push(f.name);}
var y = fields.indexOf("Button3.0");
var r = fields.splice(y,1);
var y1 = fields.indexOf("Text2.0");
var r = fields.splice(y1,1);
var y2 = fields.indexOf("Button3.1");
var r = fields.splice(y2,1);
var y3 = fields.indexOf("Text2.1.1.1.0.0");
var r = fields.splice(y3,1);
var y4 = fields.indexOf("Text2.1.1.1.1");
var r = fields.splice(y4,1);
var y5 = fields.indexOf("Check Box3");
var r = fields.splice(y5,1);
var y6 = fields.indexOf("Text3.0.0");
var r = fields.splice(y6,1);
var y7 = fields.indexOf("Text3.1.0");
var r = fields.splice(y7,1);
var y8 = fields.indexOf("Text3.1.1.0");
var r = fields.splice(y8,1);
var y9 = fields.indexOf("Text3.1.1.1.1");
var r = fields.splice(y9,1);
var y10 = fields.indexOf("Text3.1.1.1.0");
var r = fields.splice(y10,1);
var y11 = fields.indexOf("Agency Report Number");
var r = fields.splice(y11,1);
var y12 = fields.indexOf("Offense#");
var r = fields.splice(y12,1);
var y13 = fields.indexOf("Text7.1.0.1.0.0.0");
var r = fields.splice(y13,1);
var y14 = fields.indexOf("Text7.1.0.1.1.0.0.0");
var r = fields.splice(y14,1);
var y15 = fields.indexOf("Text7.1.0.1.1.0.0.1.0");
var r = fields.splice(y15,1);
var y16 = fields.indexOf("Text9.0.0");
var r = fields.splice(y16,1);
var y17 = fields.indexOf("Text9.0.1.0.1.0.1");
var r = fields.splice(y17,1);
var y18 = fields.indexOf("Text9.0.1.0.1.1.1.1.1.1.1.1.1.1.1");
var r = fields.splice(y18,1);
var y19 = fields.indexOf("Text9.0.1.0.1.1.1.1.1.1.1.1.0.1.1");
var r = fields.splice(y19,1);
var y20 = fields.indexOf("Text9.0.1.0.1.1.1.1.1.1.1.1.0.1.0.1.0");
var r = fields.splice(y20,1);
var y21 = fields.indexOf( ");
var r = fields.splice(y21,1);
var y22 = fields.indexOf("Text9.0.1.0.1.1.1.1.1.1.1.1.0.1.0.1.1.1.1.1.1.1.1.0.1.1.1.1.1.1.1.1.1.1.1.1.1.0");
var r = fields.splice(y2,1);
var y23 = fields.indexOf("Text9.0.1.0.1.1.1.1.1.1.1.1.0.1.0.1.1.1.1.1.1.1.1.0.1.1.1.1.1.1.1.1.1.1.1.1.0.0.1.0.0");
var r = fields.splice(y3,1);
var y24 = fields.indexOf("Text5.1");
var r = fields.splice(y,1);
var y25 = fields.indexOf("Text8");
var x = app.alert("STOP! DO NOT clear this form until you saved it under Suspect name; LAST, First & Date. Do you want to clear this form?", 2, 2);
if(x == 4)
this.resetForm(fields);

 


At this line: var y21 = fields.indexOf( "); you are missing " it should be: var y21 = fields.indexOf("");

2 replies

sbc707Author
Known Participant
September 19, 2021

---------------------------------------------------------------------------------------------------------------------

Clear Form (Mouse Up)

 

THIS IS WHAT I AM IN NEED OF AND CANNOT FIND THE CODE TO DO IT

 

When you click the “Clear Form” button a Message box should popup and say:

 

“STOP!

DO NOT clear this form until you saved it under Suspect name; LAST, First & Date.

Do you want to clear this form?”

                                                                                               YES     NO

 

When you click “YES” the form should be cleared and the Message box should close and those fields I have unchecked in Reset-a-form should not be deleted but they are. If I delete Reset-a-form then all the unchecked fields will still be deleted which I do not want.

When you click “NO” the Message box should close and the form will NOT be cleared.

---------------------------------------------------------------------------------------------------------------------

Above is what I want to do but it appears that so far there is no javascript that does exactly that. This code pops up a Message box which I want but it has a RED X in the upper left corner of the message box. When I click OK the Clear Button it immediately erases everything on the form except the fields I have turned off. There is no OFF / ON button in the Message box. This is the code that does that.

 

if (app.alert("STOP! \nDO NOT clear this form until you save it under prisoner name; LAST, First & Date?")==4) this.mailDoc;

 

I am beginning to assume that there is no javascript that can do what I need. If I have to just use the Acrobat Reset-a-form without javascript I can do that as much as I would rather not.

---------------------------------------------------------------------------------------------------------------------

 

try67
Community Expert
Community Expert
September 19, 2021

I already answered this question of yours... To reiterate, replace mailDoc with resetForm.

sbc707Author
Known Participant
September 19, 2021

What you gave me did not work. OK I just replaced mailDoc with resetForm and a Message box pops up with a RED X in the upper left corner and only an OK button. When I click the OK button nothing happens. Perhaps I did not explain it right so here is a better explanation.

---------------------------------------------------------------------------------------------------------------------

Clear Form (Mouse Up)

 

THIS IS WHAT I AM IN NEED OF AND CANNOT FIND THE CODE TO DO IT

 

When you click the “Clear Form” button a Message box should popup and say:

 

“STOP!

DO NOT clear this form until you saved it under Suspect name; LAST, First & Date.

Do you want to clear this form?”

                                                                                               YES     NO

 

When you click “YES” the form should be cleared and the Message box should close and those fields I have unchecked in Reset-a-form should not be deleted but they are. If I delete Reset-a-form then all the unchecked fields will still be deleted which I do not want.

When you click “NO” the Message box should close and the form will NOT be cleared.

---------------------------------------------------------------------------------------------------------------------

Nesa Nurani
Community Expert
Community Expert
September 18, 2021

Try this as Mouse UP event of "Clear Form" Button:

var x = app.alert("STOP! DO NOT clear this form until you saved it under Suspect name; LAST, First & Date. Do you want to clear this form?", 2, 2);
if(x == 4)
this.resetForm();

sbc707Author
Known Participant
September 18, 2021

Thank you all for that info. I played with it and got it working. All I did was delete the Save As and keep only the Javascript and now it works perfectly. 4,000 cops will be very happy this Monday.

Thank you again,

Lance