Skip to main content
Participating Frequently
Sep 24, 2025 5:34 PM UTC
Question

Create field showing all required fields have been populated

Hi, I have a form with a number of required fields.  The form isn't submitted online, just emailed to me.

I would like to add a field at the top of the page "Form Complete" that would turn green or show a checkmark when all required fields have been entered.  I have marked each field as being required or not in the properties of each one.  I believe that I need a java script to loop through the fields and validate that required fields are populated.  Can anyone help me with that? Thank you!

28 replies

Participant
Sep 26, 2025 9:36 PM UTC

That’s a smart idea a quick visual check saves time. It’s like getting a mid taper fade, clean and polished so everything looks just right at a glance.

Translate
Thom Parker
Community Expert
Community Expert
Sep 24, 2025 7:12 PM UTC

I'd do this one a little differently.  Use the default value as an indicator.  

Use a text field for this calculation script. 

Note that the script skips buttons, which cannot be required, and signature fields, which need to be validated differently. 

 

var nComplete=0, nRequired = 0;
for(var i = 0; i < this.numFields; i++)
{
    var oFld=this.getField(this.getNthFieldName(i));
    if((oFld.type != "button") && (oFld.type != "signature")) {
        if(oFld.required){
            nRequired ++;
            if(oFld.defaultValue != oFld.value) nComplete++;
        }
     }
}

if(nComplete == nRequired){
    event.value = "All Required Fields Complete (" + nRequired + " required)";
    event.target.fillColor = color.green;
}
else{
    event.value = "Missing " + (nRequired-nComplete).toString + " Required Fields out of " + nRequired;
    event.target.fillColor = color.red;
}

 

 

Translate
Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
PDF Automation Station
Community Expert
Community Expert
Sep 24, 2025 10:16 PM UTC

This line:

if(oFld.defaultValue != oFld.value) nComplete++;

will return a false positive if the field has a default value other than null and the field is manually cleared.

Translate
Thom Parker
Community Expert
Community Expert
Sep 25, 2025 5:25 PM UTC

Hmm, then the values need an explicit conversion to keep them in the same context. 

 

I've added a simple conversion function to the code. 

// Convert null, 0, and blanks to an empty string
function NullConvert(cIn){return (Number(cIn)==0?"":cIn);}

var nComplete=0, nRequired = 0;
for(var i = 0; i < this.numFields; i++)
{
    var oFld=this.getField(this.getNthFieldName(i));
    if((oFld.type != "button") && (oFld.type != "signature")) {
        if(oFld.required){
            nRequired ++;
            if(NullConvert(oFld.defaultValue) != NullConvert(oFld.value)) nComplete++;
        }
     }
}

if(nComplete == nRequired){
    event.value = "All Required Fields Complete (" + nRequired + " required)";
    event.target.fillColor = color.green;
}
else{
    event.value = "Missing " + (nRequired-nComplete).toString() + " Required Fields out of " + nRequired;
    event.target.fillColor = color.red;
}

 

Translate
Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
PDF Automation Station
Community Expert
Community Expert
Sep 24, 2025 6:17 PM UTC

Enter the following script as a custom calculation in the text field that you want to change color if all required fields are completed and change the 5 in the script to the number of required fields:

var count=0;
for(var i = 0; i < this.numFields; i++)
{
var fieldName = this.getNthFieldName(i);
var oFld=this.getField(fieldName);
if(oFld==null){continue}
if(oFld.required==true && oFld.value!="")
{count++}
}

count==5?event.target.fillColor=color.green:event.target.fillColor=color.transparent;
Translate