2 Replies Latest reply on Aug 11, 2014 1:04 AM by try67

    Checkboxes and varibles in variable names?


      I'm not sure the title is too clear for what I'm looking for so I shall clarify.

      Normally I try to use Google ninja skills to figure this out, but I can't seem to find the answer anywhere.

      The problem, first and foremost is that when a checkbox is unchecked, it's value is set to "Off". If I could change that to "0" it would save me heaps of trouble. Currently I have the checked value set to "1".

      I would also like to clarify that I am a relative novice when it comes to java, although I have tinkered with Lua and Ruby in the past so program logic makes some sense to me. But forgive me for any blatant mistakes or shortcuts I might be overlooking.


      The question is simple. If any of 5 checkboxes are checked I want the total cumulative value to be positive.


      This is what I'm working with, making an interactive D&D character sheet for me and some friends. Was supposed to make life simpler over paper, but now it's a personal challenge.

      Boxes are numbered/listed as follows S_(Skill) [Such as Appraise, Bluff, etc.], A skill modifier. In the case of this image the relevant Mod is INT. Then we have the proficiency checkboxes. Due to there being over 40 skills, with up to 5 classes I opted to use the Multiple copy function to parse them out for me. They have been numbered as such. 1.n.i, with "n" being the row and "i" being the column. Both starting at zero. (1.0.0, 1.0.1, 1.0.2, 1.0.3, 1.0.4. Then the next row for Bluff. 1.1.0 1.1.1 etc.) Then we have Ranks invested in the skill. Ranks.n (Again. "n" being the row.) Then RFS.n and Misc.n. Same logic. And, if applicable the Armor Check Penalty which is universal. There is also the factor of whether the skill can be used untrained or not.


      The issue I'm having is that if any of the 5 checkboxes are checked, Ranks are worth full points. If not, they're only worth half. But since I cant get all 5 checkboxes to equal "0" when tallied, I just get a trail of "OffOffOffOffOff"

      I've figured out a little. But I don't think it's anywhere near good enough. Variables in the code are filled out by way of this example for Appraise.


      //Input current Row

      var n = 0

      //Input Untrained use True/Fale

      var untrained = True

      //Armor Check Penalty applies? True/False

      var acp = False

      //Synergy Skill? True/False

      var ss = False

      //Variable list

      var skill = this.getField("INT").value;      //change ability value (INT, STR, CHA etc.) as the skill dictates.

      var ranks = this.getField("Ranks.0").value; //Is there a way to simplify this with the row variable. Like this.getField("Ranks." + n).value; type deal? This is where the variables in names comes in.

      var rfs = this.getField("RFS.0").value;

      var misc = this.getField("Misc.0").value;

      //Check the checkboxes

      var check = this.getField("1.0.0").value + this.getField("1.0.1").value + this.getField("1.0.2").value + this.getField("1.0.3").value +this.getField("1.0.4").value;

      //Would love to simplify this into a smaller check. Maybe a "for i = 0,4 do" loop or something? Again, variables in names. Would also love to swap the "0" in 1.0.i for an "n" if possible.



      var synergy = 0

      if ( ss = true ) {

      //Copy Start Here if more than one synergy skill

           if ( this.getField("skillNameRank").value > 5) {      // Replace skillNameRank with proper call. Ex. Bluff has a Rank call of "Rank.1"

                var synergy = synergy + 2;

           } else {

                var synergy = synergy + 0;


      //Copy End here



      //Calculate for Skill Bonus

      if ( untrained == False ) {

           event.value = 0

      } else {

           if ( check > 0 ) {

                var proficient = 1

           } else {

                var proficient = 2


           if ( acp == True ) {

                var acPenalty = this.getField("ACP").value

           } else {

                var acPenalty = 0


           event.value = skill + ( ranks / proficient ) + rfs + synergy + misc - acPenalty;




      As you can see. Implementing this across over 40 different skills would get tiresome if I had to go though and change all of the variables references for each and every solitary one. So I'm trying to simplify it. To a few variables relevant to each skill. Which, while more complicated with limited knowledge seems to be ultimately the best route to look into. I tried to make this as clear as possible to limit the possible room for error in misinterpretation by giving a clear understanding of what I'm looking for and what I'm using it for.

      Please, if you respond to this with corrections or additional code, let me know what and why so I might implement and understand it better in the future. If you ave any questions I will try to supply the answer to the best of my ability.

      Even the greatest tools in the world are but hunks of metal to those who do not know how to use them. But the simplest tools can create a masterpiece from one who knows exactly what to do.

        • 1. Re: Checkboxes and varibles in variable names?
          try67 MVP & Adobe Community Professional

          - It's not possible to change the default "Off" value of a check-box.


          - To include a variable in the name of a field you use the + operator. For example:



          - To convert a value to a number use the Number() constructor. This will convert non-number strings (like "Off") to zero.


          - You have quite a lot of issues with your code. For example:

          * You're using the assignment operator (=) instead of the comparison operator (==) in your if-statements.

          * Your boolean values (True, False) are incorrect. JS is case-sensitive so you must make sure you use the correct spelling of things.

          I recommend that you spend some time learning the core-JS syntax. This will make it easier to develop your Acrobat script.

          For some information about core-JS see: http://www.w3schools.com/js/default.asp


          • 2. Re: Checkboxes and varibles in variable names?
            try67 MVP & Adobe Community Professional

            Sorry, I made a mistake in the reply above.


            Using the Number constructor on non-numeric strings does not result in zero but in the NaN object (Not A Number).

            To handle such cases you can use the isNaN() method to then convert them to zero and use in your calculations (or ignore, or whatever).