Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Fillable PDF Form - Custom JavaScript to throw alert and change text colour

Explorer ,
Jun 05, 2024 Jun 05, 2024

Urgent... Please help!

 

Good day all. Please i am in serious need of your help and this is very urgent. I need to get this out in 5 hours to my client.

 

So, there is this fillable pdf form i created for my client and the client is requesting that i create specific fields to ONLY accept specific correct answers. Also, if the answers are wrong, the field should retrun back an error by maybe highlighting red error background or anything that would show its an error. Besides, he doesnt  want a drop down menu or something.

 

For example: If the response to a text field is supposed to be "HOME" , if the user types in HOUSE, the form should return an error until the words HOME has been typed in. This is just a random scenario/example i just made.

 

Please can anybody help me out with a java script that can help me achieve this for my client. I really do not want to lose this job.

 

Thank you in advance.

TOPICS
JavaScript , PDF forms
3.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
2 ACCEPTED SOLUTIONS
Community Expert ,
Jun 06, 2024 Jun 06, 2024

You can use something like this as the field's custom Validation script:

 

if (event.value && event.value!="HOME") {
	event.target.textColor = color.red;
	app.alert("INCORRECT ANSWER!");	
} else event.target.textColor = color.black;

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 07, 2024 Jun 07, 2024
LATEST

Copy-paste the field in the attached PDF.

Beware that JavaScript is case sensitive, so "HOME" is not "Home" or "home".

 


Acrobate du PDF, InDesigner et Photoshopographe

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 06, 2024 Jun 06, 2024

You can use something like this as the field's custom Validation script:

 

if (event.value && event.value!="HOME") {
	event.target.textColor = color.red;
	app.alert("INCORRECT ANSWER!");	
} else event.target.textColor = color.black;
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 06, 2024 Jun 06, 2024

Thank you. But i get this error message. As shown in the screenshot.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 06, 2024 Jun 06, 2024

Remove " at the begin and end.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 06, 2024 Jun 06, 2024

Remove the quotes you added at the beginning and at the end of the script.

 

Capture_2406061300.png


Acrobate du PDF, InDesigner et Photoshopographe
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 06, 2024 Jun 06, 2024

Thanks. It accepted the javascript now. But it seem not to respond to the instruction. It still does not respond to the javascript. Maybe i am entering it in the wrong place. 

 

I selected the text field and clicked on the properties. Then i clicked on ACTION menu. 

 

Question:

1. What trigger do i select in this instance. I have tried almost all the options in there.

2. What action do i select? I have tried RUN A JAVASCRIPT

 

Like i said before, i have successfully entered the script and it shows Run A Javascript like in the screenshot below. But even if i type my name MARK in the text field, it accepts it and saves instead of rejecting it as an error. I want the word HOME only to be accepted. It should reject all other words and pop up as INCORRECT ANSWER as in the script.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 06, 2024 Jun 06, 2024

Add the script at Validate.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 06, 2024 Jun 06, 2024

You should read this, it's very useful: https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/JS_API_AcroJS.html#document-event-...


Acrobate du PDF, InDesigner et Photoshopographe
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 06, 2024 Jun 06, 2024

Thanks for the resource. But, it even got me lost. Am just a newbie to this process.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 06, 2024 Jun 06, 2024

Just use the code I provided, and follow the instructions carefully. Don't add, delete or improvise anything, and you'll see that it works fine.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 06, 2024 Jun 06, 2024

Yes i did. But the field doesn't even respond or run the javascript. I am thinking i entered the code in the wrong place,  i really dont know.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 07, 2024 Jun 07, 2024
LATEST

Copy-paste the field in the attached PDF.

Beware that JavaScript is case sensitive, so "HOME" is not "Home" or "home".

 


Acrobate du PDF, InDesigner et Photoshopographe
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines