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
July 6, 2023
Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Thom Parker
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
February 26, 2019

Hello Thom,

I didn't know that you can group those combo boxes like that. You're right then, it will make the script much shorter as you only write it for one set of combo boxes.

Could you please help me modify that code so I fully understand how it should look like?

if (!event.willCommit) {

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

     var b = this.getField("Dropdown3");   <-- 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"]); }

}

I've also used a script to check if all fields are filled. It works ok as it shows all the pages that containt empty fields but I would like to add a message that all fields are ok.


If the fields are group named, then this code will do the same as your code above.

if(!event.willCommit)

   this.getField("Grp1").getArray().forEach(function(a){a.setItems((event.change=="YES")?["", "YES", "NA", "NO"]:["NA"]);});

Create a new thread for your new question.

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