Copy link to clipboard
Copied
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.
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
That's just how you assign the value to the field that's being calculated.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
The way you did it should work fine... Why do you think it's not usable like that?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Sorry, I don't follow what you mean... How would you like it to look like, if not like this?
Copy link to clipboard
Copied
Like a list:
Copy link to clipboard
Copied
Use "\n" inside the string to add a line-break.
Copy link to clipboard
Copied
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\n6. 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:
Copy link to clipboard
Copied
I don't know why that displayed so oddly above, but hopefully you get the idea.
Copy link to clipboard
Copied
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>
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
What kind of "tweaking" are you after?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
You can add spaces and tabs, but that's about it. It can be done manually, I think, but not with a script.
Copy link to clipboard
Copied
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.....
Copy link to clipboard
Copied
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>
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Makes my brain hurt to think about that. Thanks.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now