Manariba
Manariba

Reputation: 376

Change source of image field with javascript in Adobe Acrobat

I have a listbox in an Adobe Acrobat form. When I change the value of the listbox, the source of the image field has to be changed with a javascript script:

enter image description here

As a first step, I tried to change the src in javascript, so not yet with the listbox:

var logo = this.getField("companylogo"); // button field
logo.buttonImportIcon("C:\Users\VincentJanssens\Downloads\Blauw.png")

But even this code isn't working. Thank you for getting me started!

Upvotes: 0

Views: 601

Answers (1)

joelgeraci
joelgeraci

Reputation: 4937

The code can be very simple if you set the fields up to allow for that. The first step is to create buttons for each of the images you want to be available. Name these buttons such that the Export Value of the item in the Dropdown matches exactly. Set these buttons to Hidden and Read Only in the General tab. enter image description here

Then add a button where you want the various images to appear on your form. Set this field to read-only too. Now, set up the Dropdown to Commit the selected value immediately and add the following JavaScript to the Format script of the dropdown. Replace the string 'displayImage' with the name of the button field you placed on your form.

 this.getField("displayImage").buttonSetIcon(this.getField(event.target.value).buttonGetIcon())

enter image description here

Now each time the list item changes, the script will run and use the Export Value of the field to get the button icon from the button with the same name as the export value.

I've posted a working example file here.

Upvotes: 1

Related Questions