Update javascript to checkboxes in PDF form based upon pre-populated text field from database
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
Move the code to a doc-level script and change the first line to:
if (this.getField("FieldName").valueAsString!="")
Copy link to clipboard
Copied
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";}
}

