Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

item list to automatically change text box

New Here ,
Aug 15, 2022 Aug 15, 2022

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!

TOPICS
PDF forms
3.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 15, 2022 Aug 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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 01, 2023 Feb 01, 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.  

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 01, 2023 Feb 01, 2023

this is the sample code that's not working:
var CatalogData = { Cardiohelp:{ print: "Info about Cardiohelp"}, Ecmo:{ print: "Info about Ecmo"}, Rotaflow:{ print: "Info about Rotaflow"}, Lamp:{ print: "Info about Lamp"}, Appple:{ print2: "Info about Apple"}, Mango:{ print2: "Info about Mango"}, Orange:{ print2: "Info about Orange"} };

function SetFieldValues(cName)

{

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

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

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 01, 2023 Feb 01, 2023

Where does you use the function?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 01, 2023 Feb 01, 2023
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 01, 2023 Feb 01, 2023

In the function, both ".print" and ".print2" are used, but the entries in  "CatalogData" do not contain both members. 

Otherwise there are no obvious issues with the code? Did you look in the console window to see if any errors were reported?

 

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 01, 2023 Feb 01, 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 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 01, 2023 Feb 01, 2023

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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 02, 2023 Feb 02, 2023

yes, I miswording it, your code does works, and I like your elegant idea to put all data in the same container via SetFieldValues, so i tried to make this to work for this purpose. 

Your new solution works great, but I want to keep the previous result without effecting the second dropdown, right now, when i pick the second one the first one goes blank. is that possible? 

 

Thank you once again.  

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 02, 2023 Feb 02, 2023

Use 2 different functions. One function for dropdown 1 the other for dropdown 2.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 02, 2023 Feb 02, 2023

@Bernd Alheit Thank you, i thought about that too, but I'm beginner on using jc on pdf, so i don't know what other functions i can create? can you elaborate?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 02, 2023 Feb 02, 2023

Like this:

 

function SetFieldValues1(cName)
{
  this.getField("Opis1").value = CatalogData[cName].print;
}

function SetFieldValues2(cName)
{
  this.getField("Opis2").value = CatalogData[cName].print2;
}

And use this functions at the dropdowns.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 02, 2023 Feb 02, 2023

@Bernd Alheit - this resulting with the same outcome 'undefined' 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 02, 2023 Feb 02, 2023

Share the form.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 02, 2023 Feb 02, 2023

Here is the file with Bernd fix:

https://drive.google.com/file/d/1guWBiy56g6zwHHq3uzBYI5XLzplkS0Vc/view?usp=share_link 

and here is the file with custom calculation script if you prefer that one:

https://drive.google.com/file/d/1MAoP5ruKhIsFaKPbnmQr52ayZy0IIUxW/view?usp=share_link 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 02, 2023 Feb 02, 2023
LATEST

Thank you so much @Nesa Nurani , now I know what @Bernd Alheit meant to "use this functions at the dropdowns" I thought SetFieldValues is the name when you put the JC in the beginning not on the code, not on individual dropdowns. But now its clear. Thanks again, now i can use this solutions on much more dropdowns.
cheers...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 15, 2022 Aug 15, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines