Skip to main content
Participating Frequently
October 11, 2018
Question

Indesign form fields change border color for required fields and add a save button

  • October 11, 2018
  • 4 replies
  • 1799 views

Using latest version of InDesign, I'm trying to find out how to write some JS in order to change the default red border around a text field marked required.

I have been unsuccessful so far with my code below. I have added it to the scripts user folder but when I run it I receive an error.

if (event.value=="1") {

event.target.fillColor = color.red

} else if (event.value=="2") {

  event.target.fillColor = color.green

} else if (event.value=="3")  {

event.target.fillColor = color.blue

} else if (event.value=="4") {

event.target.fillColor = ["RGB", 1, 1, 0];

} else {

event.target.fillColor = color.white

}

Does anyone have an idea on how to change the colors dynamically once input is added to a field?

Secondly, is there a way to add a button to save the pdf once it's filled out instead of clicking file/save, calling another method with JS that isn't well known that would call the save feature?

Thanks in advance!

This topic has been closed for replies.

4 replies

Participating Frequently
October 11, 2018
Inspiring
October 11, 2018

Any scripting you do would have to be done in Acrobat.

Participating Frequently
October 11, 2018

Thank you for the tutorial, however it is missing some pieces to actually call the function from a button click. Do you just name a button and write out document.getElementByName("buttonName").onClick() etc?

I can't seem to find any tutorial on how you actually handle click events inside InDesign or just attach a function to a button to be called once clicked.

Participating Frequently
October 11, 2018

So there isn't a way to simply write

document.getElementById("myBtn").addEventListener("click", doSomething);

where doSomething() is my function?

Participating Frequently
October 11, 2018

Absolutely, I did not know it had more than one location and I placed the code above in the Application folder.

The error is from InDesign when I click on the script in the application folder.

*********************************************************************************

Error number: 2

Error string: event is undefined

Engine: mail

File: c:\InstallDir'Adobe InDesign CC 2018\Scripts\ScriptsPanel\forms.jsx

Line: 4

Source: if (event.value=="1"){

*********************************************************************************

Inspiring
October 11, 2018

Can you clarify where you placed that code? If you placed it in a folder-level JavaScript, it won't do anything. What error do you get, exactly? It also doesn't change the border color. The fillColor property controls the background color, and the border color for a field is controlled with the strokeColor property. You can't change the required field border color with JavaScript - it's a user preference.

Regarding saving, see this tutorial: https://acrobatusers.com/tutorials/how-save-pdf-acrobat-javascript