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

Dropdown menu Custom Script

New Here ,
Jul 23, 2024 Jul 23, 2024

Copy link to clipboard

Copied

Hello and thanks in advance. 

I am new to JS and willing to crash and burn to only learn and get better.

I am creating a fillable vehicle inspection form in acrobat.

I am wanting to create a script that when I pull down the employee in the employee dropdown then it will prefill the constants "Vehicle" - vehicle make, model and year, Lic# - License plate number, and Veh_ID - company assigned fleet ID. 

Veh and Lic are both drop down boxes with the first option blank to allow custom text. Veh_ID is a text field. 

Am I on the riight track or have I totally derailed.

Thanks

The scprit that I am working with looks like:

// Define the drop-down menu options and corresponding values

const options = {

    "Option 1": "Last, First1",

    "Option 2": " Last, First2",

    "Option 3": " Last, First3"

};

 

// Get the drop-down menu element

const dropdown = document.getElementById("Name"); 

 

// Get the PDF fields to be filled in

const field1 = document.getElementById("Vehicle"); 

const field2 = document.getElementById("Lic#");

const field3 = document.getElementById("Veh_ID");

 

// Add an event listener to the drop-down menu

dropdown.addEventListener("change", function() {

    // Get the selected option

    const selectedOption = dropdown.value;

 

    // Fill in the PDF fields based on the selected option

    switch(selectedOption) {

        case "Option 1":

            field1.value = options[2];

            field2.value = options[3];

            field3.value = option [4];

            break;

        case "Option 2":

            field1.value = "BR549";

            field2.value = options[3];

            field3.value = "";

            break;

        case "Option 3":

            field1.value = "";

            field2.value = "";

            field3.value = options[selectedOption];

            break;

        default:

            field1.value = "123456";

            field2.value = "032527";

            field3.value = "186546";

            break;

    }

});

TOPICS
How to , JavaScript , PDF forms

Views

94

Translate

Translate

Report

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 ,
Jul 24, 2024 Jul 24, 2024

Copy link to clipboard

Copied

You can't use browser javascript (e.g. getElementById) in a PDF form.

Votes

Translate

Translate

Report

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
New Here ,
Jul 25, 2024 Jul 25, 2024

Copy link to clipboard

Copied

LATEST

Thanks, Next Question...

Is there a way to do it?

Votes

Translate

Translate

Report

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