Skip to main content
Known Participant
January 15, 2024
Question

Hiding Text fields and check boxes depending on user input

  • January 15, 2024
  • 1 reply
  • 253 views

Hi,

 

I have a form that requires some text fields and check boxes to be hidden if a serial number that is inputted by the user contains certain numbers/ letters for example:

 

I would like all text fields to be shown if the initial box is empty/ if the form is cleared however, if the user inputs a serial number such as ABCD22440ABD12345 i would like the following boxes hidden: "Stuffer Box", "Waffle Plates", "Check Box13.7" and "Check Box14.5".

 

if ther serial number does not contain 2244 i would like "Packer Guard" and "Check Box13.3" to be hidden

 

if i can get that working i can probably get everything else i require to work.

 

Thank you

This topic has been closed for replies.

1 reply

Thom Parker
Community Expert
Community Expert
January 15, 2024

Here's an article on exactly this topic:

https://www.pdfscripting.com/public/Hiding-and-Showing-Form-Fields.cfm

https://www.pdfscripting.com/public/How-to-write-an-If-statement.cfm

 

To find specific text in a string, use the "indexOf()" function.  

Here's some example code. It's not complete for the conditions you've mentioned. 

 

if(this.getField("serial").valueAsString.indexOf("2244") > -1)

{

    ... Hide/Show fields associated with this codition...

}

else

{

    ... Hide/Show fields associated with this codition...

}

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often