Planet PDF Forum Planet PDF Forum
  New Posts New Posts RSS Feed - Form Level Validation of Dropdowns
  FAQ FAQ  Forum Search   Register Register  Login Login


Hi, welcome to the Foxit Planet PDF Forum. If you have PDF or Adobe Acrobat questions then the right place to ask them is here, in this forum.

Form Level Validation of Dropdowns

 Post Reply Post Reply
Author
mnbarradeen View Drop Down
New Member
New Member


Joined: 30 Aug 2013
Points: 5
Post Options Post Options   Quote mnbarradeen Quote  Post ReplyReply Direct Link To This Post Topic: Form Level Validation of Dropdowns
    Posted: 30 Aug 2013 at 2:57pm
I have a PDF form I am working on in Adobe Acrobat Pro which is near entirely made up of Dropdowns as input option for people filling the form out.  I would like to include a javascript on/in a button that checks to make sure that each dropdown field has had an option selected (in other words something other than SELECT has been selected.  I would also like the box around the dropdown to turn red if the word 'select' is still in the drop down.

Below is an example script that does exactly this but only for text fields.  How should it be modified or should I use completely new code? I have at least 200 dropdown fields so I do want to avaoid having to reference every single field individually.

//Checks to see if there are any empty text fields on the page
//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));
     
     if (f.value!=""){
        f.lineWidth = 0
        f.strokeColor = color.transparent     
     }
     
    else 
     f.strokeColor = color.red;
     f.lineWidth = 5
     }

//Checks to see if there are any empty text fields on the page
//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));
     
     if (f.value==""){
        app.alert("You must fill in all required fields before submitting.");
 T.readonly = false; 
F.readonly = false; 
}   }   


     
Back to Top
Sponsored Links


Back to Top
gkaiseril View Drop Down
Senior Member
Senior Member


Joined: 15 Jul 2011
Location: USA
Points: 4107
Post Options Post Options   Quote gkaiseril Quote  Post ReplyReply Direct Link To This Post Posted: 30 Aug 2013 at 5:25pm
Have you looked at testing the default value for the fields?
 
 
Back to Top
mnbarradeen View Drop Down
New Member
New Member


Joined: 30 Aug 2013
Points: 5
Post Options Post Options   Quote mnbarradeen Quote  Post ReplyReply Direct Link To This Post Posted: 31 Aug 2013 at 2:27am
I am a newby to JavaScript, and only got this code from someone online. So could you please elaborate on your post (thanks for answering by the way)
Back to Top
gkaiseril View Drop Down
Senior Member
Senior Member


Joined: 15 Jul 2011
Location: USA
Points: 4107
Post Options Post Options   Quote gkaiseril Quote  Post ReplyReply Direct Link To This Post Posted: 01 Sep 2013 at 8:14pm
You can test all fields except button and signature. If you have a signature you will need to add validation for that field type. Button fields obviously do not have a value or default value.
 

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 = color.red;
          f.lineWidth = 3;
          bResult = true; // report a field not changed;
        } // end value same as default value;
  } // end field type;
   } // 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;
}
 
 
 
Back to Top
gkaiseril View Drop Down
Senior Member
Senior Member


Joined: 15 Jul 2011
Location: USA
Points: 4107
Post Options Post Options   Quote gkaiseril Quote  Post ReplyReply Direct Link To This Post Posted: 01 Sep 2013 at 8:30pm
Correction for script:
 

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 = color.red;
          f.lineWidth = 3;
          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;
}
 
 
 
Back to Top
mnbarradeen View Drop Down
New Member
New Member


Joined: 30 Aug 2013
Points: 5
Post Options Post Options   Quote mnbarradeen Quote  Post ReplyReply Direct Link To This Post Posted: 02 Sep 2013 at 5:11am
Mate, you are an absolute legend.  That worked perfectly.  Is there any way that I can get your email and every now and then have you look at some simple scripts if needed.  I would remunerate you of course.  Two other things:
1) Do you know of any online courses you could recommend to learn JavaScript
2) Would you consider the script you wrote for me a)easy b)medium c)hard?
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

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

This page was generated in 0.016 seconds.