Skip navigation
Currently Being Moderated

Document level script to display zeros in calcuated field

Jun 17, 2012 7:13 AM

Tags: #script #field #javascript #calculation #hide #validation #zeros

I have created a form, with the calculated fields set to read only, and with a validation script of

 

if (event.value == 0) event.value = '';

 

(so that the calculated fields do not display as $0.00)

 

All but four of the calculated fields are named Item.0, Item.1 etc., plus there are SubTotal, ShippingCharge, CCFee and Total fields that need to stay blank until data is entered into the form.

 

Initially, I tried to add the script as a document level script, but it didn't work and I'm thinking it needs more to the script to use at the document level, but I have no idea what more it needs.

 

 

 

Where did I go wrong?  It certainly would be quicker to add calculated fields if I didn't have to add that validation script to each.

 
Replies
  • Currently Being Moderated
    Jun 17, 2012 11:27 AM   in reply to BeardedLady

    Hi BeardedLady

     

    Do you want the document level script to "display" or "hide" the zeros.

    I'm thinking the zeros are displayed by default.

    Why would you put a validation script to hide the zeros and then a document level script to display them?

     

    Ron A

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 17, 2012 2:21 PM   in reply to BeardedLady

    Even with a document level script you would need to call it in every calculated field.

     

    I you were to write "app.alert("Hello World");" as a document level function, it would only execute when the PDF was initialized or opened and not again as long as the PDF remained open.

     

    If you rote a document level function using JavaScript like:

     

    function Hello() {

    appp.alert"Hello World, I am a function");

    return true;

    }

     

    It would never run until called  with  a JavaScript statement like "Hello();"

     

    So even with a document level script and preferably a function, you still would need to edit every calculation to call the function or the script would never run.

     

    You could also create a document level function to suppress the zero display and then write more code to add the call to this function to the calculated fields.

     

    You need to learn more about the scope of items, how events are processed within a PDF, what functions are and how to use them effectively. You might want to start with getting or linking to a copy the Acrobat JS API Reference.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points