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

How to prevent calculated fields from displaying zero?

Mentor ,
Oct 12, 2017 Oct 12, 2017

I have a PDF form that does some simple arithmetic: taking numerical entries from the user, adding or subtracting them, and then displaying the results in another field. Right now, all my calculation fields display 0.00, and they update as you add data. But if an user would rather print the form and hand write the numbers, how do you prevent the form from displaying (and printing) 0.00 in the calculated fields? I've tried this, and it doesn't work:

var cash = this.getField("Total Cash on Hand");
var petty = this.getField("Petty Cash");
var diff = cash.value - petty.value;
if (cash.value == "NaN" || petty.value == "NaN") { event.value = "" } else event.value = diff;
TOPICS
Acrobat SDK and JavaScript
735
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

LEGEND , Oct 12, 2017 Oct 12, 2017

I would use the valueAsString property for retrieving the values of the field values for cash and petty.

event.value = "";

var cash = this.getField("Total Cash on Hand");

var petty = this.getField("Petty Cash");

if (cash.valueAsString != "") {

event.value = cash.value - petty.value

I would expect you only need to test the cash on hand for a value and assume the petty cash is zero unless you need that value to explicitly entered.

Using the valueAsString property of a field retrieves the actual contents

...
Translate
LEGEND ,
Oct 12, 2017 Oct 12, 2017

I would use the valueAsString property for retrieving the values of the field values for cash and petty.

event.value = "";

var cash = this.getField("Total Cash on Hand");

var petty = this.getField("Petty Cash");

if (cash.valueAsString != "") {

event.value = cash.value - petty.value

I would expect you only need to test the cash on hand for a value and assume the petty cash is zero unless you need that value to explicitly entered.

Using the valueAsString property of a field retrieves the actual contents of a field and does not perform any automatic reformatting or formatting of the value of the field. JavaScript automatically changes a null string to zero and removes leading zeros from fields formatted as a numeric or percentage, while the valueAsString property retains the null value or leading zeros of the field.

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
Mentor ,
Oct 13, 2017 Oct 13, 2017
LATEST

Thanks very much!

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 ,
Oct 13, 2017 Oct 13, 2017

You should place this as a Validation script:

event.target.textColor = event.value == 0 ? color.white : color.black;

If value is zero, it is turned to white (adjust to the background color) so it becomes invisible on screen and on print.

Without breaking any following calculation process with a NaN value.


Acrobate du PDF, InDesigner et Photoshopographe
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