Skip to main content
Known Participant
March 13, 2017
Answered

button click to show field only if text field is populated

  • March 13, 2017
  • 1 reply
  • 1057 views

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.

This topic has been closed for replies.
Correct answer try67

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;

1 reply

try67
Community Expert
Community Expert
March 13, 2017

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

pdfUser1Author
Known Participant
March 14, 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.

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
March 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;