Skip to main content
Known Participant
June 6, 2024
Answered

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

  • June 6, 2024
  • 4 replies
  • 2718 views

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.

This topic has been closed for replies.
Correct answer JR Boulay

Copy-paste the field in the attached PDF.

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

 

4 replies

JR Boulay
JR BoulayCorrect answer
Braniac
June 7, 2024

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
JR Boulay
Braniac
June 6, 2024
Acrobate du PDF, InDesigner et Photoshopographe
Mark BenAuthor
Known Participant
June 6, 2024

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

try67
Braniac
June 6, 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.

JR Boulay
Braniac
June 6, 2024

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

 

Acrobate du PDF, InDesigner et Photoshopographe
Mark BenAuthor
Known Participant
June 6, 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.

Bernd Alheit
Braniac
June 6, 2024

Add the script at Validate.

try67
Braniac
June 6, 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;
Mark BenAuthor
Known Participant
June 6, 2024

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

Bernd Alheit
Braniac
June 6, 2024

Remove " at the begin and end.