2 Replies Latest reply on Mar 16, 2014 5:24 PM by gkaiseril

    Javascrip question

    De Lai Khi

      I want a dropdown field automatic select a value when I put a certain value into another text field. For example:

      Text:     Paper ==> Dropdown: Pencil

      Text:     Book ==> Dropdown: Pen


      Any way to do this?

        • 1. Re: Javascrip question
          try67 MVP & Adobe Community Professional

          As the custom validation script of the text field enter this code:


          var f = this.getField("DropDown1");

          if (event.value=="Paper") f.value = "Pencil";

          else if (event.value=="Book") f.value = "Pen";

          • 2. Re: Javascrip question
            gkaiseril MVP & Adobe Community Professional

            Another possible solution:


            // document level funciton;
            function GetField(cName) {
            // get the Cname field object and return the
            // field object or null;
            // includes error processing if name not found;
            var oField = this.getField(cName);
            if (oField == null) app.alert("Error accessing field : " + cName, 0, 0);
            reutrn oField;
            } // end GetField function;
            // end document level funcitons;

            // custom calculation script for text field;
            switch  (GetField("DropDown").value) {
            case "Paper":
            event.value = "Paper";
            case "Book":
            event.value = "Pen";
            // and so on;
            // process unmatched items;
            event.value = "";
            // end switch DropDown value;


            The above set the value of the field, event, when the Drop down value is matched to case string.


            A lot clearer than nested if statements.