Highlighted

Building a dropdown list in a dialog box

Participant ,
Nov 07, 2020

Copy link to clipboard

Copied

Hi,

I’m writing a script for a dialog box including a dropdown list.

Items of the list are depending on some variables, so I build a script line like that (here for 5 variables):

var theList="dialogBox.insertEntryInList({\"LCou\":{"+var1+": -1}});dialogBox.insertEntryInList({\"LCou\":{"+var2+": -1,"+var3+": -1,"+var4+": -1,"+var5+": -1}});";

then, in the dialog box building, I recall this string:

eval(theList);

That works fine as long as there is no space in the text of each variable, but that doesn’t work anymore as soon as there is a space.

I tried to replace this character by the Unicode character, the result is the same.

At the moment, my solution is to replace each space by an underscore…

Does anyone get an idea to solve that? I would prefer display a space when needed.
Thanks in advance.

Adobe Community Professional
Correct answer by Bernd Alheit | Adobe Community Professional

No. Use this:

+ "\"" + var1 + "\"" +

TOPICS
Acrobat SDK and JavaScript, How to, PDF forms

Views

81

Likes

Translate

Translate

Report

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

Building a dropdown list in a dialog box

Participant ,
Nov 07, 2020

Copy link to clipboard

Copied

Hi,

I’m writing a script for a dialog box including a dropdown list.

Items of the list are depending on some variables, so I build a script line like that (here for 5 variables):

var theList="dialogBox.insertEntryInList({\"LCou\":{"+var1+": -1}});dialogBox.insertEntryInList({\"LCou\":{"+var2+": -1,"+var3+": -1,"+var4+": -1,"+var5+": -1}});";

then, in the dialog box building, I recall this string:

eval(theList);

That works fine as long as there is no space in the text of each variable, but that doesn’t work anymore as soon as there is a space.

I tried to replace this character by the Unicode character, the result is the same.

At the moment, my solution is to replace each space by an underscore…

Does anyone get an idea to solve that? I would prefer display a space when needed.
Thanks in advance.

Adobe Community Professional
Correct answer by Bernd Alheit | Adobe Community Professional

No. Use this:

+ "\"" + var1 + "\"" +

TOPICS
Acrobat SDK and JavaScript, How to, PDF forms

Views

82

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Nov 07, 2020 0
Adobe Community Professional ,
Nov 08, 2020

Copy link to clipboard

Copied

At begin and end of each variable add "\"".

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 08, 2020 0
Participant ,
Nov 08, 2020

Copy link to clipboard

Copied

Thank you for your answer, but like that "var1", "var2", etc are the name of each item...

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 08, 2020 0
Adobe Community Professional ,
Nov 08, 2020

Copy link to clipboard

Copied

No. Use this:

+ "\"" + var1 + "\"" +

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 08, 2020 0
bebarth LATEST
Participant ,
Nov 08, 2020

Copy link to clipboard

Copied

Great! that works fine.

Thank you.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 08, 2020 0