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. 

Bernd Alheit
Community Expert
Community Expert
February 25, 2022

I have a date like 4/15/2021 in the "STARTDATE" form field and I have a number 12 in the "TERM" form field.

The form field that this code is in (called "ENDDATE") automatically shows, or auto populates, 4/14/2022 in it. And this works... however when I use "clear form" and then enter the same info in the "STARTDATE" and "TERM" form fields the form field I have this code in stays blank, that's how I know it doesnt work.

FYI: I have two other fields with dates that are acting the same way, they work fine until I use the "clear form" and they will no longer auto populate, or run the code.


Any error message in the Javascript console?

Bernd Alheit
Community Expert
Community Expert
February 24, 2022

What calculations does you want use on a empty form?