Copy link to clipboard
Copied
Hello,
I'm trying to create a form and would like to have the "drop-down" be able to select multipe items; ideally to filter those selections over to a separate text box or area on the form. I realize I need to use the list box option to be able to multi-select. I have two lists that I need to work with (they don't need to correlate with each other). One area has up to 7 selection items and the other has 50+. On the larger one; I'd really like to have it show only the items selected (which may be more visually pleasing in a separate area).
I'm not familiar with writing JavaScript (if that's needed), so am looking for an easy, step-by-step process.
Thank you!
Rachel
Sure. You can use this code as the custom calculation script of the text field (adjust the name of the list box field in the first line to match the one in your file, of course):
var listBox = this.getField("List Box1");
if (tyepof listBox.value=="string") event.value = listBox.value;
else event.value = listBox.value.join(", ");
Copy link to clipboard
Copied
Not possible with a drop-down field. For multiple item selection you need to use a list-box field, or a pop-up menu with check-boxes.
Copy link to clipboard
Copied
Yes, I understand I can’t do with drop down. Can you elaborate on how to do with the list box or a pop-up menu with check boxes?
Copy link to clipboard
Copied
With a list box you can copy the selected item and show them in a separate text field, using a script.
With a pop-up menu it can also be done, but it's more complicated.
Copy link to clipboard
Copied
Can you provide instructions on how to do the easier one- the list box and them populating the selected items in a separate text field; using a script?
Or both?
Thanks!
[Personal email signature removed]
Copy link to clipboard
Copied
Sure. You can use this code as the custom calculation script of the text field (adjust the name of the list box field in the first line to match the one in your file, of course):
var listBox = this.getField("List Box1");
if (tyepof listBox.value=="string") event.value = listBox.value;
else event.value = listBox.value.join(", ");
Copy link to clipboard
Copied
Thank you so much for the help!
Copy link to clipboard
Copied
I am trying this but I am getting reference error.
ReferenceError: invalid assignment left-hand side 3: at line 4
Copy link to clipboard
Copied
never mind. I got it to work.
Copy link to clipboard
Copied
any way to get this to have entries on individual lines? instead of one ofter the other?
Copy link to clipboard
Copied
Put "\n" instead of ", "
Copy link to clipboard
Copied
small typo in code above. transversed p & e in "typeof"
var listBox = this.getField("List Box1");
if (typeof listBox.value=="string") event.value = listBox.value;
else event.value = listBox.value.join(", ");
Copy link to clipboard
Copied
i've typed the code in as listed but it only seems to be giving me one of the items that are selected in the list and not all of them. Any thoughts as to what i might be doing wrong?
Copy link to clipboard
Copied
Good evening. Im reaching out b/c of all the research I've done on the web, you seem to have the best grasp of what Im attempting to accomplish. So I have this PDF form that Im trying to create a drop menu of options, where multiple selections, or "Select All" are available. I know this must be done using a list box, and I've scoured the web for code to do what I'm looking for. I think I found a really good example but I cannot seem to initalize it in Adobe PDF JavaScript Editor... here's the code... (attached)
Obviously, I would swap out '#select' with the list box field I was trying to visualize this all in. And my error starts right after the 'import' line of code. Any assistance with this is greatly appreciated. Thanks!
Copy link to clipboard
Copied
This code will not work in a PDF file. It was probably written for a web-page, which also uses JavaScript, but works in a very different way.
Like I wrote before, this is not possible to do with a drop-down menu in Acrobat. See my original reply for alternatives.
Copy link to clipboard
Copied
Understood. Is it possible to create a custom pop up menu that is a list box with check boxes for each item in the list? I could then use the code you provided above to store the multiple selections to a hidden field for exporting purposes.
Copy link to clipboard
Copied
A pop-up menu is not the same as a list box. It has a completely different structure and requires different code to display, store and load the selected value(s).
Copy link to clipboard
Copied
Thanks, I understand. It looks as though given what I'm trying to do, the pop up menu option seems to give me the most flexibility. I tried using the 'app.popUpMenu & MenuEx built-Ins but I'm not too familiar with js to custom code in check boxes. Any suggestions would be greatly appreciated. Thanks.
Copy link to clipboard
Copied
You need to use the popUpMenuEx method. You can tick an option by setting the bMarked parameter for it as true. Read the documentation and the examples for more details, but you're on the right track. The values can be saved into a hidden text field, and then loaded when the menu is shown.
Copy link to clipboard
Copied
GM, thanks for all your help. I was able to figure it out with a bit more research, but I am now running into an issue with tracking the responses for checked boxes. The first 9 or so check boxes display the correct value when checked but the 10th and subsequent text fields (which are now deleted) show 'undefined' and I'm not quite sure why. I've combed through my code and haven't noticed anything out of place that would not allow the dialog() to track the checkbox responses. I've included my code in the .txt file as an attachment, along with the menu options screen shot and the results screen shot. Any assistance is greatly appreciated. Thanks.
Copy link to clipboard
Copied
Good morning. I'd appreciate any help you could give me.
I'm using Acrobat Pro DC.
I have a drop down field (named BorC) with the following options.
Make a Selection <- default displayed option in drop down
B
C
and I have a series of checkboxes
B1, B2, B3 so on and
C1, C2, C3 and so on.
I'd like to make it where the checkboxes are default unselectable/hidden, but are basically enabled/ visble when the corresponding drop down is selected. I'm new to java but I gave it a shot but it's just not working quite right. My code is below:
if (this.getField("BorC").value=="B") {
this.getField("C1").display=display.hidden;
this.getField("C2").display=display.hidden;
this.getField("C3").display=display.hidden;
this.getField("B1").display=display.visible;
this.getField("B2").display=display.visible;
this.getField("B3").display=display.visible;
}
if (this.getField("BorC").value=="C") {
this.getField("C1").display=display.visible;
this.getField("C2").display=display.visible;
this.getField("C3s").display=display.visible;
this.getField("B1").display=display.hidden;
this.getField("B2").display=display.hidden;
this.getField("B3").display=display.hidden;
}
else if (this.getField("BorC").value=="Make a Selection") {
this.getField("C1").display=display.hidden;
this.getField("C2").display=display.hidden;
this.getField("C3s").display=display.hidden;
this.getField("B1").display=display.hidden;
this.getField("B2").display=display.hidden;
this.getField("B3").display=display.hidden;
}
Copy link to clipboard
Copied
Where did you place this code? What does "not working quite right" mean, exactly? Does it work partially? Not at all? Are there any error messages in the JS Console when you use it?