Skip to main content
Inspiring
September 21, 2023
Answered

Required fields and printing

  • September 21, 2023
  • 1 reply
  • 1438 views

I have a print button on my form. When you click on it a piece of javascript is executed to list which requried fields have not been filled in. What I want to do is print ONLY if all required fields have been completed.

 

Thanks

 

Here is the javascript.

 

function fnRequired()
{

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

}
}

This topic has been closed for replies.
Correct answer Bernd Alheit

Remove the menu action and use

this.print();

in the script.

1 reply

Bernd Alheit
Community Expert
Community Expert
September 22, 2023

Where does you use the function?

Jack157FAuthor
Inspiring
September 22, 2023

After the form is filled out, I want to give the user the ability to print it. (I don't want to get involved with email submissions at this point.) I'm looking for some way to get a clean billof health from fnRequired before allowing them to continue. One possibility is to ask if they want to print an incomplete form, but it still leaves me with the question of how to stop the execution of the javascript(s).

I would even consider asking a question of the form "yada yada not complet, do you still want to print?" I would do this inside of the function, but then I don't know how to invoke the menu action.

Bernd Alheit
Community Expert
Bernd AlheitCommunity ExpertCorrect answer
Community Expert
September 22, 2023

Remove the menu action and use

this.print();

in the script.