How to convert units within a dialog window
I'm wondering if something is possible using Extendscript for InDesign. I have this demo code:
main();
function main() {
myDialog = new Window ("dialog", "Example", undefined, {closeButton: false})
var my1Group = myDialog.add("group")
my1Group.orientation = "row"
var my1_1Group = my1Group.add("group")
var units = my1_1Group.add("panel", undefined, "Units")
units.orientation = "column"
units.alignChildren = "left"
var radio_in = units.add("radiobutton", undefined, "in");
var radio_mm = units.add("radiobutton", undefined, "mm");
var radio_pt = units.add("radiobutton", undefined, "pt");
radio_in.value = true
function selected_ubutton(rbuttons) {
for (var i = 0; i < rbuttons.children.length; i++) {
if (rbuttons.children[i].value == true) {
return rbuttons.children[i].text
}
}
}
var my1_2Group = my1Group.add("group")
my1_2Group.orientation = "row"
my1_2Group.add("statictext", [0,0,40,20], "Input:")
my1_2Group.add("edittext", [0,0,60,20], "3")
var myDisplayedUnits = my1_2Group.add("statictext", [0,0,28,20], "in")
var my1_3Group = my1Group.add("group")
my1_3Group.orientation = "column"
my1_3Group.add("button", undefined, "OK")
my1_3Group.add("button", undefined, "Cancel")
radio_in.onClick = radio_mm.onClick = radio_pt.onClick = function() {
myDisplayedUnits.text = selected_ubutton(units)
}
myDialog.show();
}
The demo code creates this dialog window:

I want it to be so that a user can select different units and have it update in the text box. Right now the demo code is only able to update the unit label next to the text box. I understand that if the only input I wanted to convert was 3 inches, then I could simply make three .onClick functions (one for each unit) and have the text update accordingly. But what I want is so that a user could change 3 to 5, or 10, or 23, or any number, and when they click "mm" or "pt" the text box updates to the converted value. Is this possible using Extendscript?
Thanks,
Ben


