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

button click to show field only if text field is populated

Participant ,
Mar 13, 2017 Mar 13, 2017

I understand how to show and hide fields with a button click. But, what I'm trying to do is, click a button and to show a field only if that field has a calculation from other fields. If no info is calculated from the other fields, then the field in question would remain hidden no matter how many times I click the button. But then, the fields that have been populated would show leaving the un-populated fields hidden. Can this be done? Here's a couple of scripts I've been playing around with but I can't get to where I want to go using them.

Script:

  this.getField("Item.1").display = display.hidden;

and/or,

if (this.getField("Item.1").valueAsString=="") event.target.display = display.hidden;

else event.target.display = display.visible;

Would someone teach me the correct script to do this and to help me out? Thanks.

TOPICS
Acrobat SDK and JavaScript , Windows
996
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

correct answers 1 Correct answer

Community Expert , Mar 14, 2017 Mar 14, 2017

Not really... Why would you need to hide a field that is empty? But never mind. You can do it like this:

var f = this.getField("Item.1");

f.display = (f.valueAsString=="") ? display.hidden : display.visible;

Translate
Community Expert ,
Mar 13, 2017 Mar 13, 2017

So you want to hide a field if it has no value, basically?

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
Participant ,
Mar 13, 2017 Mar 13, 2017

Hello, the fields I'm referring to sometimes have a sum, sometimes they don't. When they do I'd like to show them, but when they don't have anything in them they remain hidden. Only the fields which have a sum will show when I click the button. Is it possible? Know what I mean.

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 ,
Mar 14, 2017 Mar 14, 2017

Not really... Why would you need to hide a field that is empty? But never mind. You can do it like this:

var f = this.getField("Item.1");

f.display = (f.valueAsString=="") ? display.hidden : display.visible;

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
Participant ,
Mar 14, 2017 Mar 14, 2017
LATEST

Worked perfectly. Thank you. The reason I want to hide a field which is empty, well it's a little difficult to explain, but I have a table with a column with these fields. I have another field (a drop down) with percentage markups, i.e. 0%, 10%, 20%, etc. Some times the fields do a calculation. When that happens I have a button to show the column of fields. I don't want to show all the fields that calculate the percentage markup if they are empty, only the ones that have been populated are then visible. It makes for a neater form. Anyway, it now works the way I was hoping.

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