Skip to main content
lc19948958
New Participant
August 15, 2022
Question

item list to automatically change text box

  • August 15, 2022
  • 2 replies
  • 3757 views

I have no knowledge on how to use javascript etc and have searched this community for code on how to set up drop down list to auto change another text field. I have a product drop down with 2 options and i want a separate text field to change the list price.  I can't understand the code and settings i need to set this up in my Adobe pdf form.

 

The drop down is called "Item Description_Device1"

the text field is "List Price1".

 

Can someone help me create the code and tell me where i need to copy and paste it? 

Under properties, I have "options" and "Selection change" tab to enter "Execute this script".

 

Thanks!

This topic has been closed for replies.

2 replies

Nesa Nurani
Community Expert
August 16, 2022

If you have "Selection change" tab, that means you have 'List Box' field and not 'Dropdown'.

Either way, under 'Options' tab in that field where you set items, give each item export value to be the price you wish to show in field "List Price1" for that item and then in "List Price1" field under 'Calculate' tab as custom calculation script use this:

event.value = this.getField("Item Description_Device1").value;

 

You can also tick, 'Commit selected value immediately' in "Item Description_Device1" field 'Options' tab if you wish to commit value without need to click outside field first.

Thom Parker
Community Expert
August 15, 2022

Here's an article that discusses the topic:

https://acrobatusers.com/tutorials/change_another_field/

 

There's also lots of info here on list and dropdown programming in Acrobat. Although most of it is not free.

https://www.pdfscripting.com/public/List-Field-Usage-and-Handling.cfm

 

You might want also want to consider hiring a developer to help you out. 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Participating Frequently
February 1, 2023

hi, i have similar issue, with multiple dropdown list. 

I've follow your tutorial and works fine, but only for one drop down list box:

https://acrobatusers.com/tutorials/change_another_field/

 

If i am using more than one drop down, with different data set, its not working anymore with this solution, is there any other way to do it? Thank you so much.  

Thom Parker
Community Expert
February 1, 2023

no error, just returned as 'undefined' when other dropdown is choosen, its effect the other one. I don't know how to separate them or not effecting other. Earlier i tried to separate the var CatalogData and separate this.getField("Opis2").value = CatalogData[cName].print2; but not working. 

i have the sample pdf test here 


So yes, obviously if an undefined value is referenced, it returns "undefined". That's how the JavaScript engine works. So your code was already working perfectly.  It's not very helpful for us when someone says "the code isn't working" when it is. You should have asked your last question first. 

 

What you meant to say is that you need to learn how to handle undefined values. That's easy. An undefined value is the same as "null". Just need to test for it and return a default value.

Like this:

this.getField("Opis1").value = (CatalogData[cName].print == null)?"":CatalogData[cName].print;

 

Another solution is to include both values in the data, making the unused value the default. 

Or you could organize the code differently

 

this.getField("Opis1").value = "";

this.getField("Opis2").value = "";

var oData = CatalogData[cName];

if(oData){

    if(oData.print)

           this.getField("Opis1").value = CatalogData[cName].print;

    if(oData.print2)

          this.getField("Opis2").value = CatalogData[cName].print2;

}

 

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