Skip to main content
rachelle_b
Known Participant
October 3, 2017
Answered

Hide text if content in another text field is blank

  • October 3, 2017
  • 3 replies
  • 10014 views

I'm very new to JavaScript and need help hiding text in the field below if another field does not have content. In other words, I don't want acct_api: to be visible if field acctno1 is blank.


event.value="acct_api: " + this.getField("acctno1").valueAsString;

This topic has been closed for replies.
Correct answer try67

Use this:

var v = this.getField("acctno1").valueAsString;

if (v=="") event.value = "";

else event.value = "acct_api: " + v;

Edit: Forgot to add the fixed text in the code...

3 replies

rachelle_b
Known Participant
October 12, 2017

Amazing! It works great. Thank you!!

rachelle_b
Known Participant
October 12, 2017

Will this be entered in the Validate/Run custom validation script?

try67
Community Expert
October 12, 2017

No. It's a doc-level script, not a field-level script. It should be entered under Tools - JavaScript - Document JavaScripts.

try67
try67Correct answer
Community Expert
October 3, 2017

Use this:

var v = this.getField("acctno1").valueAsString;

if (v=="") event.value = "";

else event.value = "acct_api: " + v;

Edit: Forgot to add the fixed text in the code...

michellesnt
Participating Frequently
October 3, 2017

Can you help me?  I've been going around with this forever. Every time you or someone posts an answer to this leave blank scenario I try changing mine and it still shows 0%.

The % calculation works but it won't stay blank if there is no value in the field being calculated.  Since we are using a form that we want to be filled out online but still have the option for manual it is important that the field be blank if someone is printing it out. Not all completed forms will include a change in $ and %.  The Amount of Change field I got to stay blank but not the percentage.  This is what I have in the custom calculation currently.  I appreciate any help you can offer.  Thanks.

var v1 = +this.getField("Proposed Pay Rate").value;

var v2 = +this.getField("Current Pay Rate").value;

if (v2=="") event.value="";

else event.value =

// compute difference between v1 and v2 as a percentage of v2;

event.value = (v1 - v2) / v2

try67
Community Expert
October 3, 2017

Thanks for your speedy reply.  Unfortunately, it still shows the 0.00% when the other fields are empty.


A field with the Percent format can't be empty. You can set it to have no format and add the percentage symbol yourself, either in the calculation script, or (better yet) in a custom Format script.