2 Replies Latest reply on Jul 18, 2014 8:50 PM by deltaalphakilo

    attempting to populate a numerical field with input from a dropdown field and a text field

    deltaalphakilo

      This is what I'm working with so far.  The code lines are simple enough, but as I expand this to it's full size (accounting for every combination of variables) the result field seems to choke and won't auto-update as I change variables in the form. Var v comes from a drop down menu, var n is a number field.

       

      var v = this.getField("TextOptions").value;

      var n = this.getField("Number").value;

      if (v=="TextOptionA") if (n=="1") event.value = "2";

      else if (v=="TextOptionA") if (n=="2") event.value = "3";

      else if (v=="TextOptionA") if (n=="3") event.value = "3";

      else if (v=="TextOptionA") if (n=="4") event.value = "4";

      else if (v=="TextOptionA") if (n=="5") event.value = "4";

      else if (v=="TextOptionB") if (n=="1") event.value = "0";

      else if (v=="TextOptionB") if (n=="2") event.value = "0";

      else if (v=="TextOptionB") if (n=="3") event.value = "1";

      else if (v=="TextOptionB") if (n=="4") event.value = "1";

      else if (v=="TextOptionB") if (n=="5") event.value = "1";

      else if (v=="TextOptionC") if (n=="1") event.value = "2";

      else if (v=="TextOptionC") if (n=="2") event.value = "3";

      else if (v=="TextOptionC") if (n=="3") event.value = "3";

      else if (v=="TextOptionC") if (n=="4") event.value = "4";

      else if (v=="TextOptionC") if (n=="5") event.value = "4";

      else event.value = "";

       

      Also, TextOptionA, C, E, G, and I will produce the same event.value given the same n variable.  The same is true with TextOptionB, D, F, and H.  Is there a way to compress the "TextOptionX"s that will produce the same event.value given an n value into a single line?  Something along these lines (I know its wrong, but this is the idea):

       

      var v = this.getField("TextOptions").value;

      var n = this.getField("Number").value;

      if (v=="TextOptionA" or "TextOptionC") if (n=="1") event.value = "2";

      else if (v=="TextOptionA"or "TextOptionC"or "TextOptionE") if (n=="2") event.value = "3";

      else if (v=="TextOptionA"or "TextOptionC"or "TextOptionE") if (n=="3") event.value = "3";

      else if (v=="TextOptionA"or "TextOptionC"or "TextOptionE") if (n=="4") event.value = "4";

      else if (v=="TextOptionA"or "TextOptionC"or "TextOptionE") if (n=="5") event.value = "4";

      else if (v=="TextOptionB"or "TextOptionD"or "TextOptionF") if (n=="1") event.value = "0";

      else if (v=="TextOptionB"or "TextOptionD"or "TextOptionF") if (n=="2") event.value = "0";

      else if (v=="TextOptionB"or "TextOptionD"or "TextOptionF") if (n=="3") event.value = "1";

      else if (v=="TextOptionB"or "TextOptionD"or "TextOptionF") if (n=="4") event.value = "1";

      else if (v=="TextOptionB"or "TextOptionD"or "TextOptionF") if (n=="5") event.value = "1";

      else event.value = "";

       

      Something like that would reduce 220+ lines of code to about 40.  Thanks for helping out a javascript dummy.