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

Display text field based on selection in two different dropdown lists

Community Beginner ,
Sep 28, 2017 Sep 28, 2017

In Acrobat, given two dropdown lists, one with 13 items and the other with 3, the user makes a single selection in each list. The result is to display a text field based on the unique combination of these two dropdown choices. My js skills are quite limited, but I assume there is a way to do that. Any help appreciated.

TOPICS
Acrobat SDK and JavaScript , Windows
2.5K
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

correct answers 1 Correct answer

Community Expert , Sep 28, 2017 Sep 28, 2017

Sure. You can use something like this as the custom calculation script of the text field:

var v1 = this.getField("Dropdown1").valueAsString;

var v2 = this.getField("Dropdown2").valueAsString;

if (v1=="Tom" && v2=="Smith") event.value = "Manager";

if (v1=="Tom" && v2=="Roberts") event.value = "Vice-President";

if (v1=="Jane" && v2=="Becker") event.value = "CEO";

if (v1=="Rodney" && v2=="Dangerfield") event.value = "Janitor";

// etc.

Translate
Community Expert ,
Sep 28, 2017 Sep 28, 2017

Sure. You can use something like this as the custom calculation script of the text field:

var v1 = this.getField("Dropdown1").valueAsString;

var v2 = this.getField("Dropdown2").valueAsString;

if (v1=="Tom" && v2=="Smith") event.value = "Manager";

if (v1=="Tom" && v2=="Roberts") event.value = "Vice-President";

if (v1=="Jane" && v2=="Becker") event.value = "CEO";

if (v1=="Rodney" && v2=="Dangerfield") event.value = "Janitor";

// etc.

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 Beginner ,
Sep 28, 2017 Sep 28, 2017

Thanks for the swift reply try67. I basically get what you're saying there except for the event.value naming. Is that just a text field set to hidden?

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 ,
Sep 28, 2017 Sep 28, 2017

That's just how you assign the value to the field that's being calculated.

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 Beginner ,
Sep 28, 2017 Sep 28, 2017

Yes, but I guess I am unclear about how to fully implement this. Please see the pdf linked. I put the script on the LO1small textbox, but it doesn't work when choosing 1 and small in the two dropdowns. https://adobe.ly/2xJ8JP6

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 ,
Sep 28, 2017 Sep 28, 2017

Works just fine... If you set the field as visible you'll see it, too.

Also, if you set the drop-downs to commit their selected values immediately (under Properties - Options) the value will change as soon as you make a selection. As it stands the value is only applied when you exit the fields.

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 Beginner ,
Sep 28, 2017 Sep 28, 2017

Oh, OK. So I had that field set to invisible because I didn't want it to show at all until the selection was made, but with these settings, I see that it simply populates the field with the text even though the field itself is visible. I think I can work with that. Thanks so much.

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 Beginner ,
Sep 28, 2017 Sep 28, 2017

So, of course, I've come across another issue that might make this approach unusable. The content to be displayed is not just a word or two, it's a combination of several sentences (certain teaching methods out of a list). If you reload the example I uploaded above, you'll see what I mean. I put three of them in there. I need them to display like a list so they are more readable instead of wrapping like they do. Is there anything I can do about that?

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 ,
Sep 28, 2017 Sep 28, 2017

The way you did it should work fine... Why do you think it's not usable like that?

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 Beginner ,
Sep 28, 2017 Sep 28, 2017

For one thing, it's ugly. These are selections from a list of 19 things. Users expect to see them displayed in a list so it's easy to see and read what's there. When they are all strung together, it's harder to read--and you are not immediately sure if there are two there or more until you read through and see the numbers. It just should be laid out as a list.

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 ,
Sep 28, 2017 Sep 28, 2017

Sorry, I don't follow what you mean... How would you like it to look like, if not like this?

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 Beginner ,
Sep 28, 2017 Sep 28, 2017

Like a list:

  1. Gaining a basic understanding of the subject (e.g., factual knowledge, methods, principles, generalizations, theories)
  2. Developing creative capacities (inventing, designing, writing, performing in art, music, drama, etc.)
  3. Learning to analyze and critically evaluate ideas, arguments, and points of view
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 ,
Sep 28, 2017 Sep 28, 2017

Use "\n" inside the string to add a line-break.

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 Beginner ,
Sep 28, 2017 Sep 28, 2017

Nice. I guess it's too much to ask for traditional list formatting? With the line break and longer items, the wrap is messy, like this:

1. Gaining a basic understanding of the subject (e.g., factual knowledge, methods, principles, generalizations, theories); \n\n
6. Developing creative capacities (inventing, designing, writing, performing in art, music, drama, etc.;
11. Learning to analyze and critically evaluate ideas, arguments, and points of view)

Rather than this:

  1. Gaining a basic understanding of the subject (e.g., factual knowledge, methods, principles, generalizations, theories);
  2. Developing creative capacities (inventing, designing, writing, performing in art, music, drama, etc.;
  3. Learning to analyze and critically evaluate ideas, arguments, and points of view)
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 Beginner ,
Sep 28, 2017 Sep 28, 2017

I don't know why that displayed so oddly above, but hopefully you get the idea.

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 ,
Sep 28, 2017 Sep 28, 2017

Not sure I do... If you add more than one instance of "\n" you'll get

multiple line-breaks, one after another.

On Fri, Sep 29, 2017 at 1:04 AM, davidp60953449 <forums_noreply@adobe.com>

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 Beginner ,
Sep 29, 2017 Sep 29, 2017

Yes, I did that and made it look a little better, but apparently you cannot do any kind of fine tweaking of how things are formatted.

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 ,
Sep 29, 2017 Sep 29, 2017

What kind of "tweaking" are you after?

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 Beginner ,
Sep 29, 2017 Sep 29, 2017

As I described before. It's a subtle difference, but I'm more of a graphics guy than a programmer, so it matters to me. See the difference in the first group compared to the second below. It's just cleaner and a little easier to read.

Formatting.png

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 ,
Sep 29, 2017 Sep 29, 2017

You can add spaces and tabs, but that's about it. It can be done manually, I think, but not with a script.

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 Beginner ,
Sep 29, 2017 Sep 29, 2017

I'll play with it.

Now another issue (should I repost?). It occurred to me that I need a way for users to add fields as needed. In this scenario, the user inputs a student learning outcome, then chooses from the list of 13 objectives, and the aforementioned scripting happens. But I don't know in advance how many outcomes a user might have. So I cannot predict how many of these forms I need. I guess I could just put 50 in there, but for someone who has 5, that's going to be many blank pages of a form. I did a quick look and see from some older posts that there is no way to dynamically add new fields as needed. Just hoping something has changed in recent years.....

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 ,
Sep 29, 2017 Sep 29, 2017

That can be done using a Template object, which allows you to spawn copies

of a page. However, if that page includes calculation scripts it makes the

whole thing quite more complicated to implement, as the code will have to

take the new field names into account.

On Fri, Sep 29, 2017 at 5:21 PM, davidp60953449 <forums_noreply@adobe.com>

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 Beginner ,
Sep 29, 2017 Sep 29, 2017

I see. So the new page would rename a duplicated field with some automatically generated addendum like, "_B" or something? Then that breaks the calculation scripts. But there is a way to get the script to change?

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 ,
Sep 29, 2017 Sep 29, 2017

Exactly, only it's a much more complex name, but it's predictable.

No, you can't change the script. You have to write it in advance taking the naming scheme into consideration.

Try searching the JavaScript forum for "template" and "spawn". This issue was discussed several times in the past.

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 Beginner ,
Sep 29, 2017 Sep 29, 2017

Makes my brain hurt to think about that. 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