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

How to join multiple if statements in one function for doc-level form function?

Community Beginner ,
Mar 18, 2020 Mar 18, 2020

I'm using the document level function to automatically check boxes yes when a form field is populated. However, there are 4 different checkboxes that need their own if statement. How do I join multiple if statements in one function? I'm not a javascript coder so I don't know. Thanks in advance!

 

This is what I have:

 

function Checkboxes789()
{if (this.getField("contract fee").valueAsString!="")
{this.getField("Q7N").value = "yes";}
else
{this.getField("Q7N").value = "no";}

 

if (this.getField("Waived Txt").valueAsString!="")
{this.getField("7AN").value = "yes";}
else
{this.getField("7AN").value = "no";}

 

if (this.getField("lb_name").valueAsString!="")
{this.getField("Q8N").value = "yes";}
else
{this.getField("Q8N").value = "no";}

 

if (this.getField("DBNames").valueAsString!="")
{this.getField("DB9N").value = "yes";}
else
{this.getField("DB9N").value = "no";}
}

TOPICS
General troubleshooting , How to , PDF forms
1.1K
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
LEGEND ,
Mar 18, 2020 Mar 18, 2020

That should work, though you're missing a final curly brace. Also, those if statements can be simplified like:

 

getField("Q7N").value = getField("contract fee").valueAsString ? "Yes" : "No";

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
LEGEND ,
Mar 18, 2020 Mar 18, 2020

Sorry, ignore that part about the missing curly brace - I see it now.

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 Beginner ,
Mar 19, 2020 Mar 19, 2020

Thanks, but the multiple statements I have above do not work when combined together. Am I missing something?

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
LEGEND ,
Mar 19, 2020 Mar 19, 2020
LATEST

Check to see if any errors are reported in the JavaScript console (Ctrl+J). If there are none, you'll have to provide more information. Note that for a check box, the value of the field when checked is whatever you set the export value to (often "Yes", but not "yes"), and will be "Off" (but not "off", "no", or anything else) when unchecked. So you'll have to adjust your code to account for this.

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