Skip to main content
krystianR
Participating Frequently
February 21, 2019
Answered

Dropdown box - populate chosen text / blank field

  • February 21, 2019
  • 2 replies
  • 8193 views

Hello Gents,

I'm looking for a javascript that will help me populate, a chosen option from a dropdown menu. The principle is that when I choose option YES the few dropdown boxes on the other pages are blank and I'm able to choose from 3 options YES, NO and N/A.

I've tried calculation script  event.value = this.getField("Dropdown1").value; in those boxes to "read" first dropdown menu but there is a problem with that. When I choose YES it will populate that selection to other boxes and it won't let me change it. I want it to work so when I choose N\A it copies N\A and when I choose YES it will let me select if the answer to the question is YES or NO.

Thanks in advance for any sugestions.

Krystian

This topic has been closed for replies.
Correct answer Thom Parker

Got it!

if (!event.willCommit) {

var a = this.getField("204");   <--- Dropdown on other pages

     var b = this.getField("206");   <-- Dropdown on other pages

a.clearItems();

     b.clearItems();

switch (event.change) {

case "YES":

a.setItems(["", "YES", "NA", "NO"]);

              b.setItems(["", "YES", "NA", "NO"]);

break;

case "NA":

a.setItems(["NA"]);

              b.setItems(["NA"]); }

}

All I need to do now is add other combo boxes as c, d, e, ect.


Excellent news! You look at a problem long enough and thinks become clearer.

I have a couple of comments.

1) It is not necessary to clear and set the drop down items. This adds a lot of code you'll need to debug and maintain. Instead, disable the dropdowns by setting the readonly property. Much simpler.

2) Handling the "Other" fields will be much easier if you use the group naming I mentioned in the previous post

2 replies

New Participant
July 5, 2023

I would like to auto pop multiple fields with a "NA" if one of 4 selections from a dropdown list is selected.  For example,  Drop Down Box selections include: i) Married (ii) Unmarried (iii) Widow  

 

If "Unmarried is selcted, I want 5 other felds to auto populate with a "NA".  

 

If Unmarried is not slected, no auto pop

Thom Parker
Community Expert
Community Expert
July 6, 2023
Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Thom Parker
Community Expert
Community Expert
February 21, 2019

You're request is not clear.  Please try to explain what you want in simple clear terms.

However, it seems you are interested in changing another field from a dropdown.

Here is an article on that topic:

https://acrobatusers.com/tutorials/change_another_field

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
krystianR
krystianRAuthor
Participating Frequently
February 21, 2019

Hello Thom,

Thank you for quick reply.

I was bit unclear so let's start again.

My form has got one drop-down box on the first page with two options to choose: Yes and NA. This box let user to choose if that option exist or not.

If feature exist then user is choosing Yes. What should happen is that a dropdown fields in the document ( around 10 of them ) are open and blank. User can then choose one from 3 options: Yes, No and NA in those dropdown fields.

When feature is not available then users is choosing NA. What should happen after that is that NA is automatically copied in the same drop-down boxes explained above.

I hope that makes it clear a bit more.

One drop-down box controls what's happening with the other 10 drop-down boxes. NA or act as a normal box.

I've tried with the script mentioned above but it doesn't work as I want it.

Krystian

Thom Parker
Community Expert
Community Expert
February 25, 2019

Hello Thom,

add 1)

Ok so I can delete the part of the code:

a.clearItems();

but how would I add that read only property bit?

add 2

I can't group those other dropdown boxes. The thing is that every box is a different answer so if I group them and choose answer in one of them it will automatically change answers in the others. Unless I'm missing something here..?

Krystian


On a PDF, form fields are grouped by prefixing the field name with a group name with the "dot" notation.

For example:  "Grp1.Fld1"  "Grp1.Fld2" "Grp1.Fld3"

These field names are all have the same group name of "Grp1". They are all unique individual fields, with their own value.

The advantage is that they can all be collected into an array so they can be operated on together.

var aFldArray = this.getField("Grp1").getArray();

This makes it easy to work on groups of fields. 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often