Copy link to clipboard
Copied
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;
Copy link to clipboard
Copied
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...
Copy link to clipboard
Copied
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...
Copy link to clipboard
Copied
It works! Thank you so much.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Try this code:
var v1 = +this.getField("Proposed Pay Rate").value;
var v2 = +this.getField("Current Pay Rate").value;
if (v2==0) event.value="";
else event.value = (v1 - v2) / v2;
Copy link to clipboard
Copied
Thanks for your speedy reply. Unfortunately, it still shows the 0.00% when the other fields are empty.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Do you have the script you suggest to format the number to percent? I can't find one that works.
Thanks
Copy link to clipboard
Copied
The Format script is pretty simple:
if (event.value!="") event.value += "%";
Copy link to clipboard
Copied
Thanks, but that is one of the ones not working.
var v1 = +this.getField("Proposed Pay Rate").value;
var v2 = +this.getField("Current Pay Rate").value;
if (v2==0) event.value="";
else event.value = (v1 - v2) / v2;
if (event.value!="") event.value += "%";
...is the whole script I have. With that extra bit that is supposed to make the answer a percentage I only get the error message. Before adding that extra line at the bottom it gave me a .50 instead of 50%.
Copy link to clipboard
Copied
Use this:
var v1 = +this.getField("Proposed Pay Rate").value;
var v2 = +this.getField("Current Pay Rate").value;
if (v2==0) event.value="";
else event.value = (((v1 - v2) / v2) * 100) + "%";
Copy link to clipboard
Copied
That gives the same result. Same error message.
Copy link to clipboard
Copied
Change the field's Format to None.
Copy link to clipboard
Copied
Thank you. That was it. When I got rid of the percentage format I left it at number. None works now. Thanks so much.
Copy link to clipboard
Copied
To make your code easier to read and debug, I recommend doing the following:
- replace all occurrences of "v1" with "proposedPayRate"
- replace all occurrences of "v2" with "currentPayRate"
"proposedPayRate" and "currentPayRate" are more mnemonic.
Copy link to clipboard
Copied
Please refer to my original request above.
So I've run into an issue with these fields because they are calculations. In my experience, calculations often require the user to tab through 1 or more text fields before the total/answer populates the form. In this case, my Adobe Acrobat PDF is being populated by content from a different software application. As such, these fields are not populating unless the user clicks ANY checkbox or tabs through ANY field. This works great for PDFs that require the user to fill in additional fields, however I'm concerned if the user doesn't need to fill anything out on the form because these fields are not populating content. Is there any thing I can do to make this work?
Thanks for your help!
Copy link to clipboard
Copied
If the user needs to tab or edit another field before your calculations execute correctly it means there's something wrong with them. Most likely, the field calculation order is incorrect.
But the situation you describe where the values are populated from an external source is actually a valid one. The solution for it is to embed a doc-level script that executes the following command:
this.calculateNow();
That will force all the calculations to happen when the file is first opened.
Copy link to clipboard
Copied
Will this be entered in the Validate/Run custom validation script?
Copy link to clipboard
Copied
No. It's a doc-level script, not a field-level script. It should be entered under Tools - JavaScript - Document JavaScripts.
Copy link to clipboard
Copied
Amazing! It works great. Thank you!!

