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

Copy a validation java script into multiple fields

Community Beginner ,
Sep 19, 2018 Sep 19, 2018

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

TOPICS
Acrobat SDK and JavaScript , Windows

Views

570

Translate

Translate

Report

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

correct answers 1 Correct answer

Community Expert , Sep 20, 2018 Sep 20, 2018

You miss nothing. At validation the function will be executed.

Votes

Translate

Translate
Community Expert ,
Sep 20, 2018 Sep 20, 2018

Copy link to clipboard

Copied

You miss nothing. At validation the function will be executed.

Votes

Translate

Translate

Report

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 ,
Sep 20, 2018 Sep 20, 2018

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;

}

Votes

Translate

Translate

Report

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 Beginner ,
Sep 20, 2018 Sep 20, 2018

Copy link to clipboard

Copied

LATEST

Thanks, i have made the change. I have it working now.

Votes

Translate

Translate

Report

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
LEGEND ,
Sep 20, 2018 Sep 20, 2018

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.

Votes

Translate

Translate

Report

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 Beginner ,
Sep 20, 2018 Sep 20, 2018

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.

Votes

Translate

Translate

Report

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