3 Replies Latest reply on Mar 31, 2017 12:56 PM by stevenm67493853

    unit conversion


      Does anyone know of a JavaScript that would allow you to have 2 text fields, one that displays a number in Inches, and other that displays the equivalent value in Millimeters, yet both can have a value entered into it with the result being the other field re-calculating to the equivalent value in Inches or Millimeters?


      In other words, both fields would be acting as an input field AND an output display field at the same time.

        • 1. Re: unit conversion
          Joel_Geraci Adobe Community Professional

          I don't have the exact script but I can give you the trick to making it work... put the conversion calculation in a custom format script of each field. The format script in A will set the value in B and vice versa. You want to add the code to the format script because that gets executed after the value has been validated and as long as you don't set a value to the format event, it won't effect the appearance of the value.

          • 2. Re: unit conversion
            try67 MVP & Adobe Community Professional

            A bit tricky, but possible. Let's say these fields are called "Inches" and "MM".

            Enter this code as the custom validation script of Inches:

            this.getField("MM").value = event.value * 25.4;

            And this code as the custom validation script of MM:

            this.getField("Inches").value = event.value * 0.0393701;

            • 3. Re: unit conversion
              stevenm67493853 Level 1

              Thanks so much, it worked!