Copy link to clipboard
Copied
Hi all,
I'm in over my head once again. Currently trying to learn JavaScript and trying to run before I can walk. Hey ho.
How do I go about calling one of three different functions based on the user's selection from a drop-down menu?
I can only seem to get it to do A4. And it also runs the function when I click cancel (which it shouldn't do).
Any help, as always, is very much appreciated.
var myList = ["A4", "US Letter", "A4 & US Letter"];
var myDialog = app.dialogs.add({name:"PDF Export", canCancel:true});
with (myDialog )
with (dialogColumns.add())
with(borderPanels.add())
{
staticTexts.add ({staticLabel:"Select:"});
var myDropSelection = dropdowns.add({stringList:myList, selectedIndex:2});
}
if(myDialog.show() == true){
alert (myList [myDropSelection.selectedIndex])
myDialog.destroy();
}
if([selectedIndex = 0]){
exportA4();
}
if([selectedIndex = 1]){
exportUS();
}
if([selectedIndex = 2]){
exportBoth();
}
function exportA4() {//code here}
function exportUS() {//code here}
function exportBoth() {//code here}
It was almost 20 years ago the last time I used the dialogs object. š I guess it should be something like that:
var myList = ["A4", "US Letter", "A4 & US Letter"];
var myDialog = app.dialogs.add({name:"PDF Export", canCancel:true});
with (myDialog )
with (dialogColumns.add())
with(borderPanels.add())
{
staticTexts.add ({staticLabel:"Select:"});
var myDropSelection = dropdowns.add({stringList:myList, selectedIndex:2});
}
if(myDialog.show
...
A few errors with the code. When comparing things, use the == comparator, not =. Also, no need to have those items in brackets. Good to store the selection during show then check that selection after destroying.
var myList = ["A4", "US Letter", "A4 & US Letter"];
var myDialog = app.dialogs.add({name:"PDF Export", canCancel:true});
with (myDialog )
with (dialogColumns.add())
with(borderPanels.add())
{
staticTexts.add ({staticLabel:"Select:"});
var
...
Copy link to clipboard
Copied
It was almost 20 years ago the last time I used the dialogs object. š I guess it should be something like that:
var myList = ["A4", "US Letter", "A4 & US Letter"];
var myDialog = app.dialogs.add({name:"PDF Export", canCancel:true});
with (myDialog )
with (dialogColumns.add())
with(borderPanels.add())
{
staticTexts.add ({staticLabel:"Select:"});
var myDropSelection = dropdowns.add({stringList:myList, selectedIndex:2});
}
if(myDialog.show() == true){
if(myDropSelection.selectedIndex == 0){
exportA4();
}
else if(myDropSelection.selectedIndex == 1){
exportUS();
}
else if(myDropSelection.selectedIndex == 2){
exportBoth();
}
myDialog.destroy();
}
function exportA4() {
$.writeln(arguments.callee.toString().match(/function ([^\(]+)/)[1]);
}
function exportUS() {
$.writeln(arguments.callee.toString().match(/function ([^\(]+)/)[1]);
}
function exportBoth() {
$.writeln(arguments.callee.toString().match(/function ([^\(]+)/)[1]);
}
Copy link to clipboard
Copied
Hi @Kasyan Servetsky, just a little thing I noticed in passing... functions have a name property so you should be able to simply to arguments.callee.name. Tiny thing but I like it when people tell me these things so hope you don't mind either.
- Mark
Copy link to clipboard
Copied
A few errors with the code. When comparing things, use the == comparator, not =. Also, no need to have those items in brackets. Good to store the selection during show then check that selection after destroying.
var myList = ["A4", "US Letter", "A4 & US Letter"];
var myDialog = app.dialogs.add({name:"PDF Export", canCancel:true});
with (myDialog )
with (dialogColumns.add())
with(borderPanels.add())
{
staticTexts.add ({staticLabel:"Select:"});
var myDropSelection = dropdowns.add({stringList:myList, selectedIndex:2});
}
var mySel;
if(myDialog.show()){
mySel = myDropSelection.selectedIndex;
myDialog.destroy();
}
if(mySel == 0){
exportA4();
}
if(mySel == 1){
exportUS();
}
if(mySel == 2){
exportBoth();
}
function exportA4() { alert("Export A"); }
function exportUS() { alert("Export US"); }
function exportBoth() { alert("Export Both"); }
Copy link to clipboard
Copied
Thanks, guys. Both of your suggestions worked perfectly.
Copy link to clipboard
Copied
Thanks, guys. Both of your suggestions worked perfectly.
By @JustyR
Great minds think alike! š