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

JavaScript - dropdown menu

New Here ,
Jan 28, 2020 Jan 28, 2020

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!

TOPICS
Acrobat SDK and JavaScript
289
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
Community Expert ,
Jan 28, 2020 Jan 28, 2020

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

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
New Here ,
Jan 28, 2020 Jan 28, 2020

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
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
Community Expert ,
Jan 28, 2020 Jan 28, 2020
LATEST

Something like this:

if (sel)

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

 

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