Skip to main content
Participant
May 24, 2020
Answered

Alert box for a form filled under 1000 characters

  • May 24, 2020
  • 1 reply
  • 689 views

Hello everybody,

I am creating a form with a text field named as "MOTIVATION". I want a warning to appear if the number of characters (including letters, numbers and spaces) is less than 1000 characters when pressing save or close buttons. The warning will be like;

 

THE NUMBER OF CHARACTERS IS LESS THAN 1000.

DO YOU WANT TO CONTINUE?

                                                                                          YES / NO 

 

Any help will be appreciated. 

Regards

Vahap

 

This topic has been closed for replies.
Correct answer Thom Parker

You can't stop a PDF from being saved or closed. Maybe you should popup a warning when the user finishes typing in the field. Use a validation script for this.

 

Or you could have a big red text field displayed at the top or bottom of the form that doesn't go away until the field is filled correctly.

 

In any case, this code will display an alert for a field that has less than 1000 characters

 

if(this.getField("Text1").valueAsString.length < 1000)

   app.alert("Less than 1000 characters");

 

You can find out more about alert box scripts here:

https://acrobatusers.com/tutorials/popup_windows_part1/

 

1 reply

Thom Parker
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
May 24, 2020

You can't stop a PDF from being saved or closed. Maybe you should popup a warning when the user finishes typing in the field. Use a validation script for this.

 

Or you could have a big red text field displayed at the top or bottom of the form that doesn't go away until the field is filled correctly.

 

In any case, this code will display an alert for a field that has less than 1000 characters

 

if(this.getField("Text1").valueAsString.length < 1000)

   app.alert("Less than 1000 characters");

 

You can find out more about alert box scripts here:

https://acrobatusers.com/tutorials/popup_windows_part1/

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
vakarAuthor
Participant
May 25, 2020

Hi Thom,

thanks a lot for your help. 

Regards

Vahap