Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to validate a form using Javascript this.mailDoc function

New Here ,
Dec 01, 2019 Dec 01, 2019

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

 

TOPICS
PDF forms
1.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 02, 2019 Dec 02, 2019

Which values don't you want to accept, then? Just if the field is empty?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 02, 2019 Dec 02, 2019

I don't mind any value as long as the field is not empty. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 02, 2019 Dec 02, 2019

Then change:

if (f.value == 0) {

To:

if (f.valueAsString == "") {

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 03, 2020 Jan 03, 2020
LATEST

Thanks allot man! It worked!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines