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

Hide/unhide form field based on other form text field is empty or not

Explorer ,
Jan 08, 2022 Jan 08, 2022

Copy link to clipboard

Copied

Hello.

 

I am not really good with javascrip. How can I solve that I like to make a form text field only visible if the previous form text field is filled. Thanks

TOPICS
Edit and convert PDFs , How to , JavaScript , PDF forms

Views

3.3K
Translate

Report

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
1 ACCEPTED SOLUTION
Community Expert ,
Jan 09, 2022 Jan 09, 2022

Copy link to clipboard

Copied

It's possible but you will have to enter script into each field.

You will use scripts as 'custom keystroke script'.

Go to field properties -> format tab and select 'custom' then 'custom keystroke script' (when you enter script it will disappear but it will still work).

for row1:

put this in "ItemName1" field:

this.getField("MaterialNumber1").display = AFMergeChange(event).length != 0 ? display.visible : display.hidden;

put this in "MaterialNumber1" field:

this.getField("ItemQuantity1").display = AFMergeChange(event).length != 0 ? display.visible : display.hidden;

 

Repeat for other rows by changing field names in script.

View solution in original post

Votes

Translate

Report

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 ,
Jan 08, 2022 Jan 08, 2022

Copy link to clipboard

Copied

Since you didn't provide field names lets say you have "Field1" and "Field2", to hide/show "Field2" depending on "Field1" value, as validation script of "Field1" use this:

this.getField("Field2").display = event.value == "" ? display.hidden : display.visible;

Votes

Translate

Report

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
Explorer ,
Jan 08, 2022 Jan 08, 2022

Copy link to clipboard

Copied

Thank you Nena. Can It be triggered by the start of the typing and dynamic (I mean If i clear the first field in the case the second field become invisible)? There are 3 colomns and 15 rows. Only the first row is visible and i like to make visible every colomns in the following rows after start the typing in the previous. The Field names ItemName1-ItemName15/SKU1-SKU15/Quantity1-Quantity15  and the order in the ItemName->SKU->Quantity. I know the Quantity in the row validate the ItemName in the next row. With the above script it is working but isn't hide the next field if I empty the previous (I like to do it in the case both are empty). 

Votes

Translate

Report

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 ,
Jan 09, 2022 Jan 09, 2022

Copy link to clipboard

Copied

It's possible but you will have to enter script into each field.

You will use scripts as 'custom keystroke script'.

Go to field properties -> format tab and select 'custom' then 'custom keystroke script' (when you enter script it will disappear but it will still work).

for row1:

put this in "ItemName1" field:

this.getField("MaterialNumber1").display = AFMergeChange(event).length != 0 ? display.visible : display.hidden;

put this in "MaterialNumber1" field:

this.getField("ItemQuantity1").display = AFMergeChange(event).length != 0 ? display.visible : display.hidden;

 

Repeat for other rows by changing field names in script.

Votes

Translate

Report

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
Explorer ,
Jan 09, 2022 Jan 09, 2022

Copy link to clipboard

Copied

Hello Nesa. I tried it out and worked perfectly. I moved forward and added it to the last in the row with the name of the first field in the next row. This way only the first row visible and the rest is appear as required. Thank you a lot.

Votes

Translate

Report

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 ,
Jan 11, 2022 Jan 11, 2022

Copy link to clipboard

Copied

LATEST

You can read all about hiding and showing fields in this article. 

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

 

 

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

Votes

Translate

Report

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
Explorer ,
Jan 08, 2022 Jan 08, 2022

Copy link to clipboard

Copied

This is what I have.

 

Clipboard 93.jpgexpand image

Votes

Translate

Report

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