6 Replies Latest reply on Nov 26, 2008 10:33 PM by (JesseV)

    Write text based on an item of combobox

      Hello,

      I'm very new with Acrobat scripting and need some help. I've tried a number of kind of syntaxes, but the result stays the same.

      I have a combobox (Trade_mark) with 2 items: car, moto.
      I want to write a script when I select moto, then there must be write a number (1) to a field (test).

      This is what I already tried:

      var manual=this.getField("Trade_mark");
      var kind=manual.getItemAt();

      function moto(){
      var test=this.getField("test");
      test.value="1";
      }

      if kind=moto{
      moto
      };

      I have already used parentheses after moto-function and not, I already inserted ";" but the result stays always the same.
      Did I use the right syntax to call the syntax moto?
      If there are other suggestions, they are welcome too!
        • 1. Re: Write text based on an item of combobox
          Level 1
          I use Acrobat 5 for Macintosh
          • 2. Re: Write text based on an item of combobox
            gkaiseril MVP & Adobe Community Professional
            Do you understand the use of objects, operators,the syntax, and event actions of Acrobat JavaScript?

            Where exactly is the action for this script located?

            You can accomplish what you want with a "Custom calculation script" for the "test" field as simple as:

            event.value = ''; // clear field
            // if the "Trade_mark" field's value is "moto"
            if (this.getField("Trade_mark").value == "moto"){
            event.value = 1; // set event field equal to 1
            };

            You may want to look at the eSeminars on demand at the Acrobat User Community, http://www.acrobatusers.com/ .
            • 3. Re: Write text based on an item of combobox
              Level 1
              That's indeed a good suggestion! But I prefer a kind of subprograms and that's the problem. How can I create a subprogram and last but not least: How do I call a subprogram in that script?

              Example:
              program 1 in the script with the commands
              program 2 in the script with the commands

              If a field has that specific criteria, then run program 1
              If the field has another specific criteria, then run program 2

              In VBA it's "easy" but I don't know how to write it down in Javascript for Acrobat for Macintosh.
              • 4. Re: Write text based on an item of combobox
                gkaiseril MVP & Adobe Community Professional
                Try these scripts:

                // document level function
                function bTestField2Value(cField, cValue) {
                // return the logical result of the comparison of the cField's value to the cValue string
                return (this.getField(cField).value.toString() == cValue.toString() ); // return result of test as a logical value
                }
                // end document level funciton

                // custom calculation script for the 'test' field
                // if Trade_mark equals 'moto' set field to 1
                event.value = bTestField2Value('Trade_mark', 'moto')? 1: '';

                Since the document level function does not have any hard coded field name or value and does not set any field, you can use this function within any script to determine if a field value matches a value and perform a logical action as needed. So this can be use in an 'if', 'while', 'until', or 'switch' statement.
                • 5. Re: Write text based on an item of combobox
                  gkaiseril MVP & Adobe Community Professional
                  You could also create an applicaiton level script with the provided function, so you would not even need to use a document level script, but you would need to install the application script on every machine that would user your form.

                  Acrobat JavaScript is not a compiled language and does not have any object libraries, object modules, or dynamic link libraries and there is no compiler or linkage editor program as found on the big iron systems.

                  If you are serious about writing your own scripts, you really need to get Adobe's Acrobat JS API Reference and the JavaScript 1.5 Reference.
                  • 6. Re: Write text based on an item of combobox
                    Level 1
                    I will use the first suggestion. It's like you said: acrobat javascript is not a compiled language.
                    Many thanks for your suggestions and helpful information!