Skip to main content
Known Participant
April 24, 2019
Answered

I have tried adding dropdown lists to the following check without success

  • April 24, 2019
  • 1 reply
  • 1216 views

Hi

I have the following javascript in a button before a form is ready for signature which is working, which I have found on various forums. However, I need to include 2 more items

1) to include checks on dropdown lists if they are visible and required, the default value of these dropdown lists are "SELECT ITEM",

and

2) if possible I would like to have an additional message displayed if a certain checkbox called divur1 is not ticked before displaying the main message which is included in my script below

var emptyFields = [];

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

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

     if (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 fill in the following fields:\n" + emptyFields.join("\n"));

} else {

// actions to complete when all required fields completed.

app.alert("Congratulations, all fields completed, Choose your name below and Digitally sign the form. DID THE CUSTOMER AGREE TO MARKETING EMAILS IF YES PLEASE CHECK THE BOX UNDER CONTACTS IS TICKED otherwise continue");

}

this.getField("Dropdown28").display = display.visible;

this.getField("Reset").display = display.hidden;

This topic has been closed for replies.
Correct answer try67

1. Change this line:

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

To:

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

2. Add this to your code:

if (this.getField("divur1").valueAsString=="Off") app.alert("Some error message.");

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
April 24, 2019

1. Change this line:

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

To:

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

2. Add this to your code:

if (this.getField("divur1").valueAsString=="Off") app.alert("Some error message.");

Known Participant
April 24, 2019

Hi

thanks it worked but now it is requiring all my radio buttons to be checked, how would I handle these as obviously they only require one choice and they are pre-checked on a standard

try67
Community Expert
Community Expert
April 24, 2019

Not sure what you mean... If one of the radio-buttons is pre-selected, what is there to validate?