Skip to main content
Inspiring
November 3, 2013
Answered

how to add buttons in script, which on click run different codes?

  • November 3, 2013
  • 1 reply
  • 1444 views

If we run script then it should display 6 button along with ok, cancel button. If we click on button1 then the coding assciated with button1 should execute and so on.

button1

button2

button3

button4

button5

button6

Ok Cancel.

Virender

This topic has been closed for replies.
Correct answer pixxxelschubser

// DialogSimpleButton.jsx

// http://forums.adobe.com/thread/1327372?tstart=0

// how to add buttons in script, which on click run different codes?

// regards pixxxelschubser

function SimpleDialog() {

var w = new Window('dialog', '');

this.windowRef = w;

w.orientation = "column";

btn1 = w.add('button',undefined,'Button 1');

btn2 = w.add('button',undefined,'Button 2');

btn3 = w.add('button',undefined,'Button 3');

btn4 = w.add('button',undefined,'Button 4');

btnOK = w.add('button',undefined,'OK');

btnCancel = w.add('button',undefined,'Cancel');

btn1.onClick = function() {alert("Button 1");};

btn2.onClick = function() {alert("Button 2");};

btn3.onClick = function() {alert("Button 3");};

btn4.onClick = function() {alert("Button 4");};

defaultElement = btnOK;

cancelElement = btnCancel;

btnOK.active = true;

btnOK.onClick = function() {

    stuff = "your stuff";

    w.close();

    }

w.show();

}

var stuff = null;

SimpleDialog ();

if (stuff) alert(stuff);

1 reply

pixxxelschubser
Community Expert
Community Expert
November 3, 2013

Only by using a palette with BridgeTalk.

Here you can see a simple example:

http://forums.adobe.com/message/4844127#4844127

Inspiring
November 4, 2013

Hi,

I am sorry I was not clear enough to explain my requirement. the codes which will exeute will remain in a single scirpt. all in all only one script file. I am new for create button and assign code to that button so any help will be great.

button1  // alert("button1")

button2  // alert("button2")

button3  // alert("button3")

button4  // alert("button4")

button5  // alert("button5")

button6  // alert("button6")

Ok Cancel.

If i click on button2 then respective code should exceute e.g. alert("button2") in this case.

pixxxelschubser
Community Expert
pixxxelschubserCommunity ExpertCorrect answer
Community Expert
November 4, 2013

// DialogSimpleButton.jsx

// http://forums.adobe.com/thread/1327372?tstart=0

// how to add buttons in script, which on click run different codes?

// regards pixxxelschubser

function SimpleDialog() {

var w = new Window('dialog', '');

this.windowRef = w;

w.orientation = "column";

btn1 = w.add('button',undefined,'Button 1');

btn2 = w.add('button',undefined,'Button 2');

btn3 = w.add('button',undefined,'Button 3');

btn4 = w.add('button',undefined,'Button 4');

btnOK = w.add('button',undefined,'OK');

btnCancel = w.add('button',undefined,'Cancel');

btn1.onClick = function() {alert("Button 1");};

btn2.onClick = function() {alert("Button 2");};

btn3.onClick = function() {alert("Button 3");};

btn4.onClick = function() {alert("Button 4");};

defaultElement = btnOK;

cancelElement = btnCancel;

btnOK.active = true;

btnOK.onClick = function() {

    stuff = "your stuff";

    w.close();

    }

w.show();

}

var stuff = null;

SimpleDialog ();

if (stuff) alert(stuff);