Forums
Guides
Features
Media
Zelda Wiki
Patreon
    Help with Javascript in an Acrobat form
    • What I would like to do is make the selections in a drop down box change depending on the value of a text field. I have some code that is kind of working. It shows the correct selections based on the value in the text field, however, when I select anything added and try to commit the selection it immediately changes back to the option from the else statement. Here is the code:

      /*options in dropdown based on value of renown*/

      var renown = this.getField("Renown").value;

      if (renown>="2" && renown<="4") this.getField("BaseLevel").setItems(["Lv 1 Base Camp","Lv 2 Forward Camp"]);

      else if (renown>="5" && renown<="9") this.getField("BaseLevel").setItems(["Lv 1 Base Camp","Lv 2 Forward Camp","Lv 3 Main Base"]);

      else if (renown>="10" && renown<="14") this.getField("BaseLevel").setItems(["Lv 1 Base Camp","Lv 2 Forward Camp","Lv 3 Main Base","Lv 4 Command Centre"]);

      else if (renown>="15") this.getField("BaseLevel").setItems(["Lv 1 Base Camp","Lv 2 Forward Camp","Lv 3 Main Base","Lv 4 Command Centre","Lv 5 Stronghold"]);

      else this.getField("BaseLevel").setItems(["Lv 1 Base Camp"]);




      So, this is probably pretty trivial stuff, but I don't really know javascript.
      Mamimi: "I saw God the other day, by the river on a rainy afternoon. He helped a kitten that was left all alone. It's a God that only I can see. A black winged angel that came down from the heavens just for me."

      ~FLCL
    • You're looking for an event handler. Event handlers deal with conditional things like running code when a button is clicked or a key is pressed. Also, you should really use jQuery. It'll make your life a thousand times simpler, trust me. An example handler with jQuery would look like this:

      Source Code

      1. $(document).ready($('#renown').change(function{
      2. (your code here)
      3. }));


      $(document).ready() ensures that the event isn't scripted to start listening until page is fully loaded. If the javascript for the event runs before the targeted element is loaded, it will throw an error and force stop the execution of the remaining code. Not good.
      #renown is a CSS selector for an element with the ID of "renown" ie <div id="renown">, <span id="renown">, etc.

      Of course, you'll need the jQuery library to do this. Check out jquery.com for instructions. And remember: if you're using javascript, you're going to want to be using jQuery. It makes things so simple.

      EDIT: It's worth noting that many CMSes and other types of modern web software come with jQuery bundled in. Wordpress definitely does, for one. Also, if the $ isn't working as a variable, then you need to use jQuery instead. ie: $(document).ready() becomes jQuery(document).ready()
      (former) Technical administrator and developer for Zelda Universe and Zelda Wiki.
      Want to know more about ZW? Read up!
    • Thanks for the advice. I was able to figure it out a few day ago. The code was correct I was just putting it in the wrong place in Acrobat. I was putting it in the calculation property when I should have been putting it in a keypress event. Similar to what Justin suggested.
      Mamimi: "I saw God the other day, by the river on a rainy afternoon. He helped a kitten that was left all alone. It's a God that only I can see. A black winged angel that came down from the heavens just for me."

      ~FLCL