Copy link to clipboard
Copied
Hi,
I have a PDF form which acts as an inspection report for a manufacturing process at my work. I am trying to digitise the report so they can use a tablet instead of hand writing and then scanning the documents into our system.
I have a simple validation script which turns the entered text into red for certain values:
function if (event.value=="WORN") event.target.textColor = color.red;
else event.target.textColor = color.black;
However i am not having much luck copying this script to all the text fields on the document (over 200 fields).
I have tried the solution outlined in this thread: faster way to copy a validation java script into multiple fields, i have set a Document JavaScript called validateField, i have then put the following script into it:
function validateField()
{
function if (event.value=="WORN") event.target.textColor = color.red;
else event.target.textColor = color.black;
}
But when i run the JavaScript console it just adds validateField() into the Text Fields custom validation script section and not the script above. This is what i am running the the JavaScript Console:
for (i=1; i<=200; i++)
{
this.getField("Text Field Condition.1."+i).setAction("Validate",'validateField()');
}
Am i missing something?
Regards,
Tim
1 Correct answer
You miss nothing. At validation the function will be executed.
Copy link to clipboard
Copied
You miss nothing. At validation the function will be executed.
Copy link to clipboard
Copied
Your function definition is incorrect and would cause a syntax error when you try to use it.
You need to drop the second "function" term, so like this:
function validateField() {
if (event.value=="WORN") event.target.textColor = color.red;
else event.target.textColor = color.black;
}
Copy link to clipboard
Copied
Thanks, i have made the change. I have it working now.
Copy link to clipboard
Copied
You absolutely want to add ValidateField() to each field, not the lines of the script. Then, if you made a mistake or want to improve it, you only have to change the document level script, and all the fields are fixed or improved.
Copy link to clipboard
Copied
Thanks, im not sure why but i have come back to it this morning and made sure i referenced the right script and it now works.

