JavaScript - dropdown menu
Copy link to clipboard
Copied
I am trying to script a dropdown menu to spawn templates or multiple copies of the same templates (i.e., select "1", 1 copy of the template is spawned; select "2", 2 copies are spawned, etc.). The first issue is probably code (below: copied/altered from another community poster). The second issue: the actions are extremely limiting, and not one of the options includes selecting an item in a dropdown menu. So, if I select any of the "Mouse" options (Mouse up, Mouse down, etc.), the script spawns 1 copy just by clicking on the dropdown menu but nothing else. It's about as useful as scripting a button and clicking the button multiple times.
//get the value from dropdown control
var sel = this.getField("Dropdown").value;
//determine the template name
var templateName = "";
switch (sel) {
case 1 : templateName = "Template";
break;
case 2 : templateName = "Template"; templateName = "Template";
break;
case 3 : templateName = "Template"; templateName = "Template"; templateName = "Template";
break;
case 4 : templateName = "Template"; templateName = "Template"; templateName = "Template"; templateName = "Template";
break;
case 5 : templateName = "Template"; templateName = "Template"; templateName = "Template"; templateName = "Template"; templateName = "Template";
}
//if we have a template name, spawn the template
if (templateName != "") {
var t = this.getTemplate(templateName);
t.spawn();
}
Thank you!
Copy link to clipboard
Copied
For 2 copies you must execute t.spawn() two times.
Copy link to clipboard
Copied
Just to clarify, my dropdown menu will have up to 10. So, in the final part of the script, should I repeat t.spawn() 10 times?
var t = this.getTemplate(templateName);
t.spawn();t.spawn();t.spawn();t.spawn();t.spawn();t.spawn();t.spawn();t.spawn();t.spawn();...etc...
Or include that in the "case..." line:
case 1 : templateName = "Template";t.spawn();
break;
case 2 : templateName = "Template";t.spawn(); templateName = "Template";t.spawn();
break;
case 3 : templateName = "Template";t.spawn(); templateName = "Template";t.spawn(); templateName = "Template";t.spawn();
break;
etc.....
Or am I completely off on that?
Also, what about the issue with action options? They are kind of terribly ineffective for selecting from a dropdown menu. Simply clicking the dropbox (without even selecting an item) executes the script.
Thanks!
Copy link to clipboard
Copied
Something like this:
if (sel)
for (i=1; i<=sel; i++) t.spawn();

