Print Page | Close Window

Validation Javascript

Printed From: Foxit's Planet PDF Forum
Category: Lets Talk PDF
Forum Name: JavaScript
Forum Description: Discussions relating to the use of JavaScript within PDF.
Printed Date: 12 Nov 2019 at 7:40pm
Software Version: Web Wiz Forums 11.10 -

Topic: Validation Javascript
Posted By: Barra
Subject: Validation Javascript
Date Posted: 19 Feb 2014 at 11:37pm
Firstly I have no scripting experience and wouldn't mind any suggestion of how I can find someone (online) to work on any script jobs I may have?

Now to the main question:

I have created a PDF portfolio that is made up of PDF fillable forms.  This portfolio is sent to our clients, they fill them out, save them and then send the file back to us.

Someone sent me a script that validates if fields have been answered (changed from default value) and highlights any unchanged fields in red (script is at the bottom of this post).  This has worked fine but it was embedded as a SAVE button at the bottom of each document that was then merged into the PDF portfolio.

Unfortunately this has made the file size unusable (11mb) for how we use them, so we have reverted back to combining all these documents in one PDF (instead of portfolio) and having the clients just use bookmarks to navigate through the length form (it is actually a qualification assessment file).

This means that a document that has 6 pages, where before the first save button would have validated just the first 2 pages and the second save validated the next two pages etc. The save buttons now validate the entire document.

I would like to modify the below script to be able to specify that (for this example) it validates all field names with a 1 at the front (eg 1Dropbox6 or 1Text3).  and then I will embed this code into the second SAVE button but just modify it so that it validates fields that have a 2 in front (2Dropbox6 or 2Text5).  This way each SAVE button will just validate cells in the appropriate pages.

If you would like me to email a copy of the PDF doc please let me know.

function ValueEQDefaultValue() {
   var bResult = false; // assume no errors;
   //If there are, it highlights them with a red border
   for (var i = 0; i < this.numFields; i++) {
    var f =  this.getField(this.getNthFieldName(i));
    var FieldType = f.type; // get field type;
    // test all fields except button and signature;
    if(FieldType !=  "button" && FieldType != "signature" ) {
        f.lineWidth = 0;
        f.strokeColor = color.transparent;
        // see if value has not changed from default value;
        if(f.value == f.defaultValue) {
          // highlight unchanged field
          f.strokeColor =;
          f.lineWidth = 2;
          bResult = true; // report a field not changed;
        } // end value same as default value;
  } // end field type not button or signature;
  if(FieldType == "signature") {
   // enter needed validation here;
   } // end field name loop;
     return bResult; // exit function;
   } // end ValueEQDefaultValue

//Checks to see if there are any unchanged fields;
if( ValueEQDefaultValue() ) {
        app.alert("You must fill in all required fields before submitting.");
} else {
// action that all fields passed;

Posted By: try67
Date Posted: 20 Feb 2014 at 8:27am
After this line:

var f =  this.getField(this.getNthFieldName(i));

You can add something like this:

if (/^1/.test( continue; // ignore fields that don't start with "1"

- Acrobat Expert - Contact me personally at
Check out my custom-made scripts website:

Posted By: mnbarradeen
Date Posted: 20 Feb 2014 at 12:31pm
Mate you are a champion! I don't know how to repay you, my boss gave me till tomorrow to sort this problem out. If it is not pushing the friendship too much a second quick question.

With the same code what would I insert to exclude a specific field from validation. Eg exclude a field called 2Dropdown5.

Posted By: try67
Date Posted: 20 Feb 2014 at 1:17pm
Add this in the same location more or less:

if ("2Dropdown5") continue;

- Acrobat Expert - Contact me personally at
Check out my custom-made scripts website:

Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.10 -
Copyright ©2001-2017 Web Wiz Ltd. -