2 Replies Latest reply on Jan 11, 2016 10:02 AM by mollyz27531912

    Would Anyone Assist a Dummy With Adding JavaScript to PDF

    mollyz27531912

      I'm new to JavaScript in PDFs. I'm usually on the aesthetics side of the document creation, so this is angle is new to me, but I'm extremely eager to learn.

       

      I've combed the forums for the past two hours and found, what seem like, several great answers ... if I knew what I was doing with code and Java.

       

      Here's the issue:

       

      I have required fields to be filled/checked (text and radio buttons) before the document is saved.


      From what I gathered via the forums, I have to insert a specific code to a specific location, either the  field's Value or the Validation option or the Document Actions in order for anything to happen.

       

      If anyone would be patient enough to walk me through this step-by-step, I would be eternally grateful.

       

      What exactly is the code? Where does it go?

        • 1. Re: Would Anyone Assist a Dummy With Adding JavaScript to PDF
          George_Johnson MVP & Adobe Community Professional

          You can't use a script to prevent a document from being saved. The best you can do is use a script to check the required fields when the user saves the document and provide some feedback (e.g., a popup message) to the user. The best place for such a script is the "Document Will Save" event. The code you use depends on exactly what you want to happen if the user saves and some fields are incomplete. Here's a simple script that alerts the user if a text field is empty at the time the document is saved:

           

          // Script for Document Will Save event

           

          // Get the text field's value, as a string:

          var sVal = getField("zip_code").valueAsString:

           

          // Let the user know that the field is empty

          if (!sVal) {

              app.alert("The Zip code field is empty.", 3);

          }

           

           

          The code for checking check boxes is different, something like this:

           

          // Get the check box value:

          var sVal = getField("Agree").valueAsString:

           

          // Let the user know that the field is empty

          if (sVal === "Off") {

              app.alert("You must agree.", 3);

          }

          • 2. Re: Would Anyone Assist a Dummy With Adding JavaScript to PDF
            mollyz27531912 Level 1

            Foremost, thanks so much for your assistance. My apologies in advance as I'm in unchartered waters.

             

            I pasted the first code you sent into the "Document Will Save" function, but received this message:

             

            SyntaxError; before statement 4: at line 5

             

            What I need is just an overall message that pops up essentially saying

            "Hey pal, make sure you filled or checked out all the  stuff you should."


            Is this even possible?


            The doc I'm working on might have empty boxes that don't get filled. Will this change things?


            Again, sorry for being so inexperienced. Your help is greatly appreciated.