3 Replies Latest reply on Jan 14, 2013 11:34 AM by try67

    Populating one field by the value of another

    Kaokulk

      I'm trying to learn Javascript for Acrobat, so as an assignment for myself I am working on a D&D type character sheet for a friend, where one field dictates another field.

       

      So, for example, if a character is a "Fighter", they will have, say, 10 hit points, but if they are a "Cleric", they might have 8 hit points.

       

      So I have a field, called "Class".  It has a drop-down list of values: Fighter, Cleric, Rogue, and Wizard.

       

      I have another field, called HitPoints.  I went to the custom calculation, and have this:

       

      var nClass = this.getField("Class").value;

      if( nClass == "Fighter" ) event.value = 1;

      else if( nClass == "Cleric" ) event.value = 2;

      else if( nClass == "Wizard" ) event.value = 3;

      else event.value = 0;

       

      I am a skilled programmer, but not used to the syntax of Javascript.  The script above doesn't work.  It keeps defaulting to the last line (I know this because I changed the last value to "10" and every option I pick results in a 10).  Any suggestions?