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

Issue with JavaScript Code for Dropdown Interaction in Adobe Acrobat ..

Community Beginner ,
May 25, 2023 May 25, 2023

I am experiencing an issue with a JavaScript code snippet that I am using to link two dropdown fields in Adobe Acrobat. I have a "Car" dropdown and a "Car ID" dropdown, and I want the selection in the "Car" dropdown to automatically update the value in the "Car ID" dropdown.

I have followed the instructions provided and tried different code snippets, but the functionality is not working as expected. When I select an option in the "Car" dropdown, the corresponding value does not update in the "Car ID" dropdown.

 

Steps taken:

  1. Verified the field names used in the JavaScript code and ensured they match the actual field names in the PDF document.
  2. Confirmed that JavaScript execution is enabled in my PDF viewer.
  3. Tested the PDF document in different viewers to check for any compatibility issues.
  4. Checked for conflicting scripts or actions that may interfere with the dropdown functionality.
  5. Ensured that I am using the latest version of Adobe Acrobat.

 

Despite these efforts, I have been unable to resolve the issue. I am seeking assistance in identifying the problem and finding a solution for the dropdown interaction.

 

Code used:

var carDropdown = this.getField("car");
var carIDDropdown = this.getField("car ID");

carDropdown.setAction("OnBlur", "updateCarID()");

function updateCarID() {
  var selectedCar = carDropdown.value;

  switch (selectedCar) {
    case "Car 1":
      carIDDropdown.value = "1";
      break;
    case "Car 2":
      carIDDropdown.value = "2";
      break;
    case "Car 3":
      carIDDropdown.value = "3";
      break;
    case "Car 4":
      carIDDropdown.value = "4";
      break;
    default:
      carIDDropdown.value = "";
      break;
  }
}

 

Any guidance or insights into this issue would be greatly appreciated. Thank you in advance for your assistance.

TOPICS
JavaScript , PDF , PDF forms
1.4K
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 ,
May 25, 2023 May 25, 2023

Use a script at validation of the first dropdown.

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 ,
May 26, 2023 May 26, 2023

like this?

 

var dropdown1 = this.getField("Dropdown1");
var dropdown2 = this.getField("Dropdown2");

dropdown1.setAction("OnValidate", "updateDropdown2()");

function updateDropdown2() {
  var selectedOption = dropdown1.value;

  switch (selectedOption) {
    case "Dropdown1 1":
      dropdown2.value = "1";
      break;
    case "Dropdown1 2":
      dropdown2.value = "2";
      break;
    case "Dropdown1 3":
      dropdown2.value = "3";
      break;
    case "Dropdown1 4":
      dropdown2.value = "4";
      break;
    default:
      dropdown2.value = "";
      break;
  }
}
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 ,
May 26, 2023 May 26, 2023

This question is asked almost daily, start here: https://community.adobe.com/t5/acrobat-discussions/need-a-script-for-a-drop-down-menu/td-p/13599704


Acrobate du PDF, InDesigner et Photoshopographe
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 ,
May 26, 2023 May 26, 2023
LATEST

You will get the selected value with event.value

 

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