Skip to main content
Participant
July 23, 2024
Question

Dropdown menu Custom Script

  • July 23, 2024
  • 1 reply
  • 390 views

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;

    }

});

This topic has been closed for replies.

1 reply

Bernd Alheit
Community Expert
Community Expert
July 24, 2024

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

dougp300Author
Participant
July 25, 2024

Thanks, Next Question...

Is there a way to do it?