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

Update javascript to checkboxes in PDF form based upon pre-populated text field from database

Community Beginner ,
Feb 26, 2020 Feb 26, 2020

Please help to update a java script that automatically checks a yes checkbox or no checkbox, based upon a text field that is not manually entered, it's pre-populated to a mapped database field.

 

I'm using the script below to check the check boxes yes or no based upon if a text field is null or not.

However, this script only works when I manually enter data in the text field. I need it to recognize the the text field has data in it but was pre-populated from a mapping to database function that populates the text field with alphanumeric chars.

 

if (event.value.toString().length > 0)   << does this line need to be updated to recognize if field null or not, rather than greater than 0?

{this.getField("CHECKBOX").value = "yes";}
else

{this.getField("CHECKBOX").value = "no";}

 

In this case does "(event.value.toString().length > 0)" need to be changed to something else to recognize that the field is not null because the form's textfield was pre-populated with mapped data to database field. If so, what whould be the correct script update?

 

Thanks in advance!

TOPICS
General troubleshooting , How to , PDF forms
351
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 ,
Feb 26, 2020 Feb 26, 2020

Move the code to a doc-level script and change the first line to:

if (this.getField("FieldName").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
Community Beginner ,
Mar 18, 2020 Mar 18, 2020
LATEST

Hi @try67, your answer worked, of course!

However, how do I write the javascript for multiple if clauses within a function? It works when I have one, but it does not work if I have multiple if clauses. Thanks for your help, I'm not a javascript writer so I don't know.

 

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

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