Skip to main content
Participant
January 17, 2018
Answered

Script to detect unfilled fields wont detect unfilled drop downs, please help!

  • January 17, 2018
  • 2 replies
  • 587 views

I'm used the script below to detect unfilled fields on my forms. It works great however it can't detect unfilled drop downs they are set to be required. Any help would be greatly appreciated!

var emptyFields = [];

for (var i=0; i<this.numFields; i++) {

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

     if (f!=null && f.type!="button" && f.required ) {

          if ((f.type=="text" && f.value=="") || (f.type=="checkbox" && f.value=="Off")) emptyFields.push(f.name);

     }

}

if (emptyFields.length>0) {

     app.alert("Error! You must complete the following fields:\n" + emptyFields.join("\n"));

}

This topic has been closed for replies.
Correct answer try67

I wrote this code, but that's an old version of it. Replace this line:

if ((f.type=="text" && f.value=="") || (f.type=="checkbox" && f.value=="Off")) emptyFields.push(f.name);

With:

if (f.valueAsString==f.defaultValue) emptyFields.push(f.name);

2 replies

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
January 17, 2018

I wrote this code, but that's an old version of it. Replace this line:

if ((f.type=="text" && f.value=="") || (f.type=="checkbox" && f.value=="Off")) emptyFields.push(f.name);

With:

if (f.valueAsString==f.defaultValue) emptyFields.push(f.name);

The WaughAuthor
Participant
January 17, 2018

Thank you! I've been using the original code for a while now, thanks for writing it. 

Bernd Alheit
Community Expert
Community Expert
January 17, 2018

The code checks only text fields and check boxes.