Skip to main content
Known Participant
September 10, 2020
Answered

Validating Fields in JavaScript

  • September 10, 2020
  • 1 reply
  • 931 views

I was going to try and send my PDF file to look at and see what I am doing wrong, but it won't let me.

I have 1 4-page PDF form with several fields and there are 18 required fields on this 4-page form that must be filled out. Step 1 is just a text label that said, "Fill out form". On the last page at the bottom are 3 buttons. The "Step 2" button is visible and said, "Step 2 - Review your answers, then click here to submit form". This button has the following Actions:

 The first 2 Show/Hide a fields hides the Step 3 and Step 4 button. Then run the following javascript code

 

if (oField.valueAsString == oField.defaultValue) {
   oField.strokeColor = color.red;
   emptyFields.push(oField.name);

    bProcess = false;
}
else oField.strokeColor = color.transparent;

 

After the javascript code is ran, another Show/Hide for the "Step 3" button.

The "Step 2 button doesn't seem to execute the javascript code.

 

I was trying to follow this article. Either I missed something or of course not doing it right.

https://community.adobe.com/t5/acrobat/validating-fields-in-javascript-while-preventing-an-email-to-be-sent-until-all-required-fields-are/m-p/9984001?page=1 

 

Any help or suggestions would be most appreciated.

 

Thank you,

Randy Duly

 
 
This topic has been closed for replies.
Correct answer try67

Correct.

1 reply

try67
Community Expert
Community Expert
September 10, 2020

You need to do it all in a script, since the other commands will execute no matter what, and you can't control the order in which it will happen (it doesn't have to be the order in which you added them).

randyd69Author
Known Participant
September 10, 2020

So then I would have to put all of my Show/Hide fields in the JavaScript too.

Using the screenshot below to "Hide" "Step 4 - Finish" button.

 

The code would be:

getField("Step 4 - Finish").display = display.hidden;

 

Correct?

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
September 10, 2020

Correct.