Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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"){
*********************************************************************************
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
So there isn't a way to simply write
document.getElementById("myBtn").addEventListener("click", doSomething);
where doSomething() is my function?
Copy link to clipboard
Copied
Apparently it isn't possible at all with InDesign. Disappointing.
Copy link to clipboard
Copied
Any scripting you do would have to be done in Acrobat.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more