21 Replies Latest reply on Apr 27, 2008 9:05 PM by (Fred_X_Lee)

    How to increment the value of a Numeric Field box

      I have a PDF form that has a Numeric Field box in it. I want to add a link that will increment the value in the Numeric Field box when clicked on. I got as far as making the link. Using the ACTIONS tab of the LINK PROPERTIES dialog box, I selected the action: RUN A JAVA SCRIPT. Now It wants me to type in the code. Not knowing much about Java, I have tried to guess at some likely code with no success (like NumericField.Value = NumericField.Value + 1). Why are you laughing? I usually get the error message Missing: before statement 1: at line 2. I would be grateful if someone would supply the correct code lines with the correct punctuation. Im guessing it will take 3 or 4 lines. Thank you, Fred

      PS I have Adobe Acrobat 8 Professional and a PC with VISTA.
        • 1. Re: How to increment the value of a Numeric Field box
          MarkWalsh Level 4
          Use this:

          this.getField("NumericField").value++

          Where 'NumericField' is the name of your field
          • 2. Re: How to increment the value of a Numeric Field box
            Level 1
            Mark, I really appreciate your help. I tried your code line with many variations in the punctuation. The dialog box accepts it without any error messages but when I click on the resulting link, nothing happens to the value in the Numeric Field. Other links on the form work fine. Any other thoughts? Thanks, Fred
            • 3. Re: How to increment the value of a Numeric Field box
              MarkWalsh Level 4
              It works fine for me. Make sure that your field name is spelled properly, and is enclosed in quotes as above. Also, check that your numeric field is also valid.

              If it still doesn't work, open the Javascript Debugger and check to see if it displays an error when you click on the link. You may see something like the following if you have misspelled your field name:

              this.getField("NumericField") has no properties
              1:Link:Mouse Up
              • 4. Re: How to increment the value of a Numeric Field box
                Level 1
                Mark, thanks again for your prompt reply. I think I'm becoming a nuisance to you.

                I turned on the debugger and it gave me the exact message that you predicted. I had been using the name "NumericField10" as a name for the field. I thought that maybe that is not a good name as far as the link was concerned. So I changed the name to "Pointer". It did not fix the problem but I now get a different message from the debugger:

                Pointer is not defined
                1:Link:Mouse Up

                I'm not sure what you mean when you ask whether my numeric field is valid, but I can write numbers into it and save them and a different link can reset them, so I guess it is "valid".

                I do feel that we are getting close to a solution. Does the name of the field have to be declared somehow?
                • 5. Re: How to increment the value of a Numeric Field box
                  MarkWalsh Level 4
                  You have to enclose the field name in quotes, otherwise you will get that message (it's expecting a variable named Pointer if it's not in quotes). If your field is named Pointer, then the code should be:

                  this.getField("Pointer").value++
                  • 6. Re: How to increment the value of a Numeric Field box
                    Level 1
                    Yes, that's exactly how I entered the code - several times. Still didn't work. Sorry to be so much trouble. F
                    • 7. Re: How to increment the value of a Numeric Field box
                      Level 1
                      Mark, another question. Do you know any other statements that do the same thing? My computer is obstinate. Maybe it doesn't like the one I have. F
                      • 8. Re: How to increment the value of a Numeric Field box
                        gkaiseril MVP & Adobe Community Professional
                        What response are you getting?

                        If you make "Pointer"'s format to "None" what value appears?

                        An alternate approach that spells out the code and forces the value of "Pointer" to a numberic value or the number 0.

                        // increment field value of pointer by 1
                        this.getField("Pointer").value = 1 + Number(this.getField("Pointer").value);
                        • 9. Re: How to increment the value of a Numeric Field box
                          Level 1
                          Mark, I think I have figured out our problem!! You gave me the clue by asking what happens when I make the format "NONE". I think there is a "format" only in the control fields made with the FORMS menu in Acrobat. But my Numeric Fields are made in the LiveCycle Designer of Acrobat8. Since there are no "Numeric Fields" in the FORMS menu (Only "Text Fields" that can me made numeric), I didn't bother to explain that.

                          So these Designer forms are really XML forms, although the LINK PROPERTIES dialog box asks for Java statements. Maybe they must be different from the statements in the other kinds of forms. If that is the problem, it's all my fault and I'm sorry for all the extra work you did. You are a patient man.

                          Back on the subject of the Numeric Field, I also have a link on that form with an "action" to RESET the form. And it does reset my Numeric Field to a blank field. So some time ago, I looked at the Java code assigned to that link and it was something like this:

                          topmostSubform[0].Page1[0].FieldName[0]

                          I tried making all kinds of changes in that statement to see if I could make it increment the field value instead of resetting, but nothing worked.

                          Does all that clear things up, or make them worse? Thanks again, F

                          PS The last statement you sent doesn't work either, but I hope we now knot why.
                          • 10. Re: How to increment the value of a Numeric Field box
                            Patrick Leckey Level 3
                            > although the LINK PROPERTIES dialog box asks for Java statements

                            You mean JavaScript. Two completely different languages. Acrobat does not use Java in any way, shape or form. Neither does LiveCycle Designer.

                            > Maybe they must be different from the statements in other kinds of forms

                            That is correct. AcroForm JavaScript and LiveCycle JavaScript, although similar, are not interchangeable.

                            If you're using LiveCycle Designer, you can increment the value of a Numeric Field as such:

                            NumericField1.rawValue = parseInt(NumericField1.rawValue) + 1;

                            Replace NumericField1 with the name you have given your numeric field.
                            • 11. Re: How to increment the value of a Numeric Field box
                              Level 1
                              Thanks, PDL, for your reply and for straightening me out on Java vs. JavaScript. I tried your script many times and with any variations I could think up. At no time was I able to increment (or cause any change) in the value of the NumericField. Everything else works: the NumericField itself works, all other fields on the form work. They are all reset by the link "Reset Form". The only thing that doesn't work is the incrementing of a NumericField. Any more thoughts? Fred
                              • 12. Re: How to increment the value of a Numeric Field box
                                gkaiseril MVP & Adobe Community Professional
                                Have a look at:

                                http://forum.planetpdf.com/wb/default.asp?action=9&read=46297&fid=34#125330
                                • 13. Re: How to increment the value of a Numeric Field box
                                  Patrick Leckey Level 3
                                  What is the name of your numeric field?
                                  • 14. Re: How to increment the value of a Numeric Field box
                                    Level 1
                                    PDL: Thank you for your response. In one place, I named the numeric field "NumericField10". In another place it is "Pointer". Take your pick. It sounds like you have a JavaScript statement in mind. I'll be waiting.

                                    Geo Kaiser: Thank you too for that link. But the problem they are discussing there is much, much more complicated than mine. I found nothing there that I could extract for my simple task (partly because I couldn't understand much of it).

                                    Fred
                                    • 15. Re: How to increment the value of a Numeric Field box
                                      Patrick Leckey Level 3
                                      Without a sound knowledge of JavaScript, you won't be able to make much sense of Acrobat JavaScript.

                                      In LiveCycle Designer, what event are you attaching the code to (or perhaps simpler - walk me through the steps you are taking to add the JavaScript).

                                      XFA Forms (which are the types made in LiveCycle Designer) have a very strict hierarchical structure. The statement below may not work if the script is being run from a higher level in the form hierarchy that the objects themselves. Again, without knowing Acrobat JavaScript, this may not make much sense but it may be what is causing your problem. Can you give me an idea of how your form hierarchy looks?

                                      For "Pointer" it would be:

                                      Pointer.rawValue = parseInt(Pointer.rawValue) + 1;

                                      Again, this expression will not work if the script is being run from a different hierarchical level than Pointer resides in.
                                      • 16. Re: How to increment the value of a Numeric Field box
                                        Level 1
                                        To PDL:
                                        First, I tried that expression and it doesnt work. So now, as you suggested, I will go through the process I used to get to this point, leaving out no details because I dont know which detail might be important.

                                        Start Adobe Acrobat 8 Professional, click FORMS on the Getting started screen, click CONVERT AN EXISTING DOCUMENT.

                                        In the Create New Form dialog box, browse to a .BMP picture document that will be the background of the form. Two dialog boxes later, choose to place fields by hand. A couple of clicks gets the LiveCycle Designer on the screen.

                                        On the Menu Bar, click INSERT and select the MY FAVORITES library and click on NUMERIC FIELD. Drag the Numeric Field to the document. Fill out all appropriate Pallets for Field, Value, Binding, Layout, and Format.

                                        There are some 10 Numeric Fields in the document. The one we are particularly interested in here is NumericField10. It is set to be two digits long. Next to it is an arrow pointing up. I want to place a link over that arrow so that, when clicked, the value of the field is incremented. (I really wanted to put a Spin Button there like the one Microsoft Visual Basic has, but Adobe has no such button and Ive not been able to find one to insert into the library.)

                                        Click SAVE AS on the LiveCycles Menu Bar. And save the document, which is now in .PDF.

                                        Open the new PDF document. On the Acrobat Menu Bar, select ADVANCED and click on ENABLE USAGE RIGHTS IN ADOBE READER. Save the document again.

                                        Open the document again in Acrobat to add links.

                                        On the ADVANCED EDITING toolbar, click the LINK button.

                                        Draw a rectangle around the UP arrow on the form. That brings up the CREATE LINK dialog box. Under Link Action select CUSTOM. That brings up the LINK PROPERTIES dialog box.

                                        Select the ACTIONS tab. In the SELECT ACTION pull-down menu, select Run a JavaScript.

                                        In the ACTIONS box down below enter the JavaScript just as soon as PDL sends it. Click OK and get ready to celebrate.

                                        I hope that gives you all you need. Please tell me if you need more information. I cannot tell you how much I appreciate what you are doing. It means a lot to me. Thank you. Fred
                                        • 17. Re: How to increment the value of a Numeric Field box
                                          Patrick Leckey Level 3
                                          Ah ... perhaps I'm getting my posts crossed, but I thought you had mentioned using LiveCycle Designer? The process you are using does not involve LiveCycle Designer and so the provided script will not work.

                                          Try this in the same spot:

                                          var fPointer = this.getField("Pointer");
                                          fPointer.value = parseInt(fPointer.value) + 1;
                                          • 18. Re: How to increment the value of a Numeric Field box
                                            Level 1
                                            To PDL:

                                            But I did use LiveCycle Designer to make the Numerical Fields. See the third paragraph in my last message. It ends with "A couple of clicks gets the LiveCycle Designer on the screen." The next three paragraphs all take place in LiveCycle Designer. I should have made it clearer.

                                            Does that change things? I tried the two statements that you sent and they didn't work. Sorry I mislead you. Fred
                                            • 20. Re: How to increment the value of a Numeric Field box
                                              Patrick Leckey Level 3
                                              The problem here is that you're mixing AcroForms with XFA forms, which you really shouldn't be doing. You can add JavaScript to fields directly in LiveCycle Designer, which is where you would use XFA JavaScript.

                                              What you're doing is applying Acrobat JavaScript and AcroForms events to an XFA document. That will get VERY complicated for you and will drastically restrict what you can do.

                                              If you're dead set on designing your forms this way, you'll need to read the XFA Reference (available on the Adobe site) and get very familiar with the XFA model since all your non-XFA JavaScript will have to deal with XFA objects. Mostly the properties and methods required in an XFA form can be accessed in Acrobat JavaScript by accessing the "this.xfa" object.

                                              Unfortunately I sincerely do not recommend designing your forms in this method, since you are losing a lot of the new, advanced XFA functionality while restricting what you can even do with the older AcroForms technology.

                                              I suggest you learn how to do your coding in LiveCycle Designer if you're going to be designing forms using it. XFA forms and AcroForms are VERY different, and not understanding that difference before diving into development is really what got you to this point.

                                              Here is a link to the Adobe LiveCycle Designer Scripting Examples. Once you understand how to add XFA code to XFA forms, you'll be able to get what you need done.

                                              http://www.adobe.com/devnet/livecycle/designer_scripting_samples.html
                                              • 21. Re: How to increment the value of a Numeric Field box
                                                Level 1
                                                Dear PDL,

                                                You have finally made me understand the entire situation and steered me in the right direction.

                                                When you, as a novice, start a new form in Acrobat, it steers you right into LiveCycle Designer for the form fields. Using them seems like the thing to do. Then the link process gives you a link that can give the form JavaScript commands. So you would think that the two could communicate. Now that you straightened me out, I switched to fields that are not made by LiveCycle Designer and tried them with some Java statements I had gotten from others on the forum -- that had never worked before. And they worked. I now have the Spin Button I badly needed.

                                                I'm very grateful to you for your patient and steadfast help and all the time it took to give it. Thank you, Fred

                                                PS And thanks to the others who also pitched in to help. I'm now able to use some of the code that you sent.