Skip to main content
dublove
Legend
June 28, 2025
Answered

How can I click Get button and have the result calculated from box 1 displayed in box 2?

  • June 28, 2025
  • 2 replies
  • 412 views

I want to enter some characters in box 1 and then calculate it by some formula and display the result in box 2 after clicking Get button.

then:

Click the GET button to display the results in Box 2 and copy the results.

Tap the CLEAR button to clear box 2.


How can I modify the code?
Thanks a lot.

// Create a new window
var win = new Window("dialog", "Key Input Dialog");
// Group for keySymbol input
var inputGroup = win.add("group");
inputGroup.add("statictext", undefined, "keySymbol:");
var keyInput1 = inputGroup.add("edittext", undefined, "@");
keyInput1.characters = 10;


var myResult = keyInput1.text + '&&';

var keyInput2 = inputGroup.add("edittext", undefined, myResult);
keyInput2.characters = 20;


// Buttons group
var btnGroup = win.add("group");
btnGroup.alignment = "right";

var okBtn = btnGroup.add("button", undefined, "GET and COPY");   // OK
var cancelBtn = btnGroup.add("button", undefined, "CLEAR"); // Cancel

// Button click events
//okBtn.onClick = function () {
//    var selectedRadio = radio1.value ? "Option A" : "Option B";
//    var selectedDropdown = dropdown.selection.text;
//    alert(
//        "You entered: " + keyInput.text +
//        "\nRadio Selected: " + selectedRadio +
//        "\nDropdown Selected: " + selectedDropdown
//    );
//    win.close();
//};

cancelBtn.onClick = function () {
    win.close();
};

// Show the dialog
win.center();
win.show();

 

Correct answer Peter Kahrel

The answers to your questions are in here:

https://creativepro.com/files/kahrel/indesign/scriptui.html

2 replies

dublove
dubloveAuthor
Legend
June 29, 2025

Hi @rob day 

Keep an eye on this one.
I don't know how to establish a relationship between them.

Thank you very much.

Peter Kahrel
Community Expert
Community Expert
June 29, 2025

This forum is intended to deal with incidental problems, not structural and systemic ones like yours: lack of InDesign knowledge and lack of understanding about scripting.

 

I mentioned all this before, I'll do it again (one last time). Many of the questions about InDesign that you post in this forum are readily found in InDesign courses (printed and online) and reference books. That you keep coming back with often very basic things shows that you are reluctant to consult any of the recommended material. Don't be surprised therefore when fewer and fewer people will bother to answer your questions.

 

As for scrirpting, sure, that's not so easy to learn. It's certainly not something you can learn in this forum, you'll have to do the hard work yourself, then later you can have some problems cleared up here in this forum. Your approach earlier was to ask for scripts written for you from scratch. Recently you started posting some script that you found, change it a bit, say that it doesn't work, and request that someone fixes it.

 

The script you posted in this thread is a good example. Most of it is an existing script, you changed the labels a bit and ask how to get it to work for your purpose. The solution is really very simple and I provided a link to a PDF in which you can find that solution. But you don't even contemplate consulting that text.

 

But you can't come here, target people, and ask them to sort out your problems. Again, as I mentioned before, you need to hire a consultant who you can ask questions about InDesign and who can write custom scripts for you. Many people do that. It works well.

dublove
dubloveAuthor
Legend
June 29, 2025

Oh~Peter Kahrel .
There's so much time, it's a shame you wasted it.


I'm in a hurry. Knowledge can't be mastered all at once. I need to be quiet and learn slowly.

I need to go through the English translation line by line.


Thanks a lot, I've bookmarked that PDF.

I'll study it sometime.

 

Please wait a moment, I'll succeed in a moment.

Thank you.

Peter Kahrel
Community Expert
Peter KahrelCommunity ExpertCorrect answer
Community Expert
June 28, 2025

The answers to your questions are in here:

https://creativepro.com/files/kahrel/indesign/scriptui.html

dublove
dubloveAuthor
Legend
June 28, 2025

I'd like to learn to research some of the basics.

Peter Kahrel
Community Expert
Community Expert
June 28, 2025

The document's title is Beginning ScriptUI (or, ScriptUI for dummies), so that'll do for you. And it's free!