Skip to main content
Participant
Jan 28, 2020 7:09 PM UTC
Question

JavaScript - dropdown menu

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!

This topic is closed to new replies. Start a new post to keep the conversation going.

3 replies

Bernd Alheit
Community Expert
Community Expert
Jan 28, 2020 7:26 PM UTC

For 2 copies you must execute t.spawn() two times.

Translate
ejgreco78Author
Participant
Jan 28, 2020 7:32 PM UTC

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!

Translate
Bernd Alheit
Community Expert
Community Expert
Jan 28, 2020 7:41 PM UTC

Something like this:

if (sel)

for (i=1; i<=sel; i++) t.spawn();

 

Translate