Skip to main content
Known Participant
February 24, 2022
Question

Clear Form stops JS from running??

  • February 24, 2022
  • 2 replies
  • 729 views

I have a PDF that has a bunch of Form Fields, in which this commumity has helped me greatly in writing JS for, but i have noticed that when i use the "clear form" in the Tools-Forms-More Options-Clear Form, several JS's I have in the Fields-Calculate tab dont run or calculate. Is this a flaw in Adobe or is there something I need to do? I have to click in each form field and delete the contents one by one to keep the JS from getting stopped.

I also have a button I made to shortcut the "Clear Form" and it also causes the same thing.

I am using Adobe Pro 11 on Windows.

 

Thanks!!

This topic has been closed for replies.

2 replies

try67
Community Expert
Community Expert
February 24, 2022

This indicates there's an error in the code, that's causing the rest of it to not execute.

Check the JS Console for error messages.

JD5C1EAuthor
Known Participant
February 24, 2022

This is my code:

var startDate = this.getField("StartDate").valueAsString;
var term = Number(this.getField("TERM").valueAsString);
var x = startDate.split("/");
if (startDate=="" || x[1] == "01" || x[1] == "1")
event.value = "";
else {var d = util.scand("mm.dd.yyyy", startDate);d.setMonth(d.getMonth()+term); d.setDate(d.getDate()-1);
event.value = util.printd("mm.dd.yyyy", d);}

It runs just fine if i dont use the "Clear Form" option.

I will take a look at the console and see if there is a error msg. 

JD5C1EAuthor
Known Participant
February 24, 2022

This is the error I see:

ReferenceError: months is not defined
9:Field:Calculate

Why would months not be defined only after using "Clear Form"?

The Months doesn't have a problem being defined before...

Bernd Alheit
Community Expert
Community Expert
February 24, 2022

What calculations does you want use on a empty form?