Copy link to clipboard
Copied
Complete noob with JavaScript. Please help.
Using following (which seems to work) to check if required fields are filled:
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.valueAsString==f.defaultValue) emptyFields.push(f.name);
}
}
if (emptyFields.length>0) {
app.alert("Please complete the following fields:\n" + emptyFields.join("\n"));
}
Would like to run following (I've deleted personal info) ONLY when above indicates all required fields are filled:
var mySub=this.getField("Last Name").value+", "+
this.getField("First Name").value+" - text "+
this.getField("Date").value;
this.mailDoc({cTo:"sample@sample.ca",cSubject:mySub,cMsg:mySub});
But I don't know how to merge these two in the code. Any help is greatly appreciated!
In the original post where I provided you with that code, I also showed how to include code for the case where all required fields are filled. Basically just put an "else" on the "if"
Like this:
if (emptyFields.length>0) {
app.alert("Please complete the following fields:\n" + emptyFields.join("\n"));
}else{
var mySub=this.getField("Last Name").value+", "+
this.getField("First Name").value+" - text "+
this.getField("Date").value;
this.mailDoc({cTo:"sample@sample.ca",cSubject:my
...
Copy link to clipboard
Copied
In the original post where I provided you with that code, I also showed how to include code for the case where all required fields are filled. Basically just put an "else" on the "if"
Like this:
if (emptyFields.length>0) {
app.alert("Please complete the following fields:\n" + emptyFields.join("\n"));
}else{
var mySub=this.getField("Last Name").value+", "+
this.getField("First Name").value+" - text "+
this.getField("Date").value;
this.mailDoc({cTo:"sample@sample.ca",cSubject:mySub,cMsg:mySub});
}
Copy link to clipboard
Copied
Thanks, Thom. I'll try that. I hadn't seen your original post.