Skip to main content
Participant
March 31, 2017
Question

unit conversion

  • March 31, 2017
  • 2 replies
  • 380 views

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.

This topic has been closed for replies.

2 replies

try67
Community Expert
Community Expert
March 31, 2017

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;

Participant
March 31, 2017

Thanks so much, it worked!

Joel Geraci
Community Expert
Community Expert
March 31, 2017

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.