Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

[JS][CS3] Simple dialog box problem

Participant ,
Oct 26, 2009 Oct 26, 2009

Hi

I am wanting to make my script do 1 of 2 things depending on the result of a dialog box.  I cannot seem to register the users response.  Here is the code:

var myDialog = new Window('dialog', 'Confirm Changes');

myDialog.frameLocation = [600,400];

myDialog.size = [590, 250];

myImage = myDialog.add('image',[480,41,572,127],'/Macintosh HD/Applications/Adobe InDesign CS3/Scripts/Scripts Panel/Images/xxxx.png');

myPanel= myDialog.add('panel', [10,10,580,240], 'Select the action you wish to use');

//Adding Buttons

myUseExistingTextButton = myPanel.add('button', [48,190,75,25], 'Use Existing Text',{name:'select'});

myUseNewButton = myPanel.add('button', [260,190,75,25], 'Use New text as shown',{name:'select'});

myCancelButton = myPanel.add('button', [480,190,75,25], 'Cancel',{name:'select'});

myExistingTextWindow = myDialog.add('edittext',[20,40,230,200],'Existing Text');

myNewTextWindow = myDialog.add("edittext",[250,40,460,200],"New Text");

myResult = myDialog.show();

if(myResult == true)

     {

     if (myResult == 0)

                    {

                    alert("Old was selected");

                    }

     if (myResult == 1)

                    {

                    alert("New was selected");

                    }

     }

which gives the following result:

Dialog Box.jpg

All I want to do is use the selected button do do the next part of my script depending on the text selected.

I will keep on looking, and di-secting other scripts, but any help here would be nice.

Thanks as always

Roy

TOPICS
Scripting
1.7K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Engaged , Oct 27, 2009 Oct 27, 2009

myButton.onClick = function(){
                        alert("You clicked the button!");
                    }

or

myButton.onClick = myFunction;

function myFunction () {
alert("You clicked the button!");
}

--

Thomas B. Nielsen


http://www.lund-co.dk

Translate
Enthusiast ,
Oct 26, 2009 Oct 26, 2009

Your code is messed up. The coordinates make no sense.

I changed it just to get some of the picture

var myDialog = new Window('dialog', 'Confirm Changes'); myDialog.frameLocation = [600,400]; myDialog.size = [590, 250]; //myImage = myDialog.add('image',[480,41,572,127],'/Macintosh HD/Applications/Adobe InDesign CS3/Scripts/Scripts Panel/Images/xxxx.png'); myPanel= myDialog.add('panel', [10,10,580,240], 'Select the action you wish to use'); //Adding Buttons var myUseExistingTextButton = myPanel.add('button', [48,190,188,220], 'Use Existing Text',{name:'select'}); var myUseNewButton = myPanel.add('button', [260,190,360,220], 'Use New text as shown',{name:'select'}); var myCancelButton = myPanel.add('button', [480,190,575,220], 'Cancel',{name:'select'}); var myExistingTextWindow = myPanel.add('edittext',[20,40,230,180],'Existing Text'); var myNewTextWindow = myPanel.add("edittext",[250,40,460,180],"New Text"); myDialog.show();

Anyways, there is no way in your code defining what happens when button is clicked. why should one button be 0 and the other 1. Where did you define that.

You need an click event for each button, which exits dialog and defines what to do for that button etc..

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 27, 2009 Oct 27, 2009

Thank you Steven for your reply. 

I admit I often go around the houses, but the dialog box I was making was all good with the co-ordinates I was using.

I was stuck on the actions for the buttons as I said in my post, and that is where I was needing assistance.  I will look at your code, and no doubt use it for my needs.

Thanks again for your very quick response, I am constantly amazed by this forum.

Cheers

Roy

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 27, 2009 Oct 27, 2009

Can anyone let me know how to add the 'onClick. command to carry out the selected function?  I will keep looking in the meantime.

Cheers

Roy

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Oct 27, 2009 Oct 27, 2009

myButton.onClick = function(){
                        alert("You clicked the button!");
                    }

or

myButton.onClick = myFunction;

function myFunction () {
alert("You clicked the button!");
}

--

Thomas B. Nielsen


http://www.lund-co.dk

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 27, 2009 Oct 27, 2009

Thanks for that Thomas.

Quite simple really, but unless you know it....

Anyway, I am getting a runtime error when I add the destroy() line for the dialog:

function ExistingText()

{

alert("Use Existing Text");

myDialog.destroy();

}

I have used this before but I guess not with ScriptUI. Should I use something else?

Cheers

Roy

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 27, 2009 Oct 27, 2009

I have been trying lots of options, and myDialog.close(); does it!

Cheers

Roy

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 27, 2009 Oct 27, 2009

Hi.

One more little thing, when I use this line below, the variable 'myPara2.contents' does not wrap in the box.  Is there a property I need to change to allow this?

var myExistingTextWindow = myPanel.add('edittext',[20,20,230,180],myPara2.contents);

Cheers

Roy

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Oct 27, 2009 Oct 27, 2009
LATEST

Here is code created with RapidScriptUI in about 2 minutes. It includes multiline editbox, dimensions without using co-ordinates  that display accurately cross platform and simple to edit code for beginners like you to learn and understand (This is a free advertisement).

var rapidDlg = new Window('dialog',"Confirm Changes",undefined); buildWindow(); rapidDlg.show(); function buildWindow(){ // Properties for rapidDlg.Panel1      rapidDlg.Panel1 = rapidDlg.add('panel',undefined,"Select the action you wish to choose");      rapidDlg.Panel1.margins= [20,20,20,20];      rapidDlg.Panel1.orientation = "row"; // Properties for rapidDlg.Panel1.Group1      rapidDlg.Panel1.Group1 = rapidDlg.Panel1.add('group',undefined);      rapidDlg.Panel1.Group1.orientation = "column"; // Properties for rapidDlg.Panel1.Group1.EditText1      rapidDlg.Panel1.Group1.EditText1 = rapidDlg.Panel1.Group1.add('edittext',undefined,"Existing Text", {multiline:true});      rapidDlg.Panel1.Group1.EditText1.preferredSize.width = 200;      rapidDlg.Panel1.Group1.EditText1.preferredSize.height = 100; // Properties for rapidDlg.Panel1.Group1.ExistingText      rapidDlg.Panel1.Group1.ExistingText = rapidDlg.Panel1.Group1.add('button',undefined,"Use Existing Text"); rapidDlg.Panel1.Group1.ExistingText.onClick = ExistingText_Clicked; // Properties for rapidDlg.Panel1.Panel2      rapidDlg.Panel1.Panel2 = rapidDlg.Panel1.add('panel',undefined,undefined);      rapidDlg.Panel1.Panel2.alignment = [' ','fill']; // Properties for rapidDlg.Panel1.Group2      rapidDlg.Panel1.Group2 = rapidDlg.Panel1.add('group',undefined);      rapidDlg.Panel1.Group2.orientation = "column"; // Properties for rapidDlg.Panel1.Group2.EditText2      rapidDlg.Panel1.Group2.EditText2 = rapidDlg.Panel1.Group2.add('edittext',undefined,"New Text", {multiline:true});      rapidDlg.Panel1.Group2.EditText2.preferredSize.width = 200;      rapidDlg.Panel1.Group2.EditText2.preferredSize.height = 100; // Properties for rapidDlg.Panel1.Group2.NewText      rapidDlg.Panel1.Group2.NewText = rapidDlg.Panel1.Group2.add('button',undefined,"Use New text as shown"); rapidDlg.Panel1.Group2.NewText.onClick = NewText_Clicked; // Properties for rapidDlg.Button3      rapidDlg.Button3 = rapidDlg.add('button',undefined,"Cancel", {name:"cancel"});      rapidDlg.Button3.alignment = ['right',' ']; } function ExistingText_Clicked(){      alert(this.text +  ' was clicked!'); } function NewText_Clicked(){      alert(this.text +  ' was clicked!'); }

Steven

http://scriptui.com

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines