How to validate a form using Javascript this.mailDoc function
Copy link to clipboard
Copied
I have a PDF form with a submit button to Outlook by running a Javascript command.
I have a few fields tagged as 'Required' and I also have a validation script which checks to see all said fields are filled in before submitting it.
Problem is, my code doesnt accept the value/digit zero and still rejects the submission.
How do I change the code to accept the zero digit and proceed to submission?
Any help is very much appreciated. Btw I got the code from the web, I'm no Java expert lol.
var is_form_ok = true; for (var i=0; i<this.numFields; i++) { var f = this.getField(this.getNthFieldName(i)); if (f.type == "text" && f.required) { if (f.value == 0) { is_form_ok = false; i = this.numFields; // stop the loop } } } if (is_form_ok) { // all required fields contain data app.alert("OK"); } else { app.alert("Please fill in all required fields"); }
Copy link to clipboard
Copied
Which values don't you want to accept, then? Just if the field is empty?
Copy link to clipboard
Copied
I don't mind any value as long as the field is not empty.
Copy link to clipboard
Copied
Then change:
if (f.value == 0) {
To:
if (f.valueAsString == "") {
Copy link to clipboard
Copied
Thanks allot man! It worked!

