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

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

krystianR
krystianRAuthor
Participating Frequently
March 1, 2019

Yes, just add another line of code for the second group. Be sure to change the field group name and switch the list values.


Thanks Thom,

if(!event.willCommit)

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

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

The only problem I found with this is that when you choose Option1 it switches values correctly but when you choose Option2 it sets both boxes to values YES, NO and then you have to choose it again to place NA into Option1 assigned boxes

Any suggestions?.