Skip to main content
Participant
Jan 17, 2018 10:07 AM UTC
Answered

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

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 is closed to new replies. Start a new post to keep the conversation going.
try67
try67Correct answer
Community Expert
Jan 17, 2018 10:24 AM UTC

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);

3 replies

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
Jan 17, 2018 10:24 AM UTC

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);

Translate
The WaughAuthor
Participant
Jan 17, 2018 10:27 AM UTC

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

Translate
Bernd Alheit
Community Expert
Community Expert
Jan 17, 2018 10:19 AM UTC

The code checks only text fields and check boxes.

Translate