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

JavaScript for action button to change fill color of text field, radio button and check box

New Here ,
Apr 26, 2022 Apr 26, 2022

Hi 

 

I am preparing an adobe form and have some text fields, radio buttons and check boxes that change fill color at different events. I have all the JavaScripts for this working all right. 

Now, I want to add an action button to reset the form at "Mouse Up" event. I got the action button to reset all the text fields, radio buttons and check boxes using the "Reset a form" at "Mouse Up" event. However, the fill colors of text fields, radio buttons and check boxes does not go back to transparent when clicking on the reset form action button. 

 

For example, I have a check box (lets call it CheckBox1). When the check box is selected it runs two JavaScripts, one that changes the fill color of the check box itself and one that changes the fill color of a text field that goes with the check box (lets call it TextField1). The two JavaScripts for CheckBox1 are these: 

 

this.getField("CheckBox1").fillColor = event.target.value == "Off" ? color.transparent : color.yellow;

 

this.getField("TextField1").fillColor = event.target.value == "Off" ? color.transparent : color.yellow;

 

How come, when I click the action button for resetting the form, it only clears the check box but does not change the fill colors back to transparent?

 

Can I add a JavaScript to the reset action button that changes the fill colors, of all the fields (text fields, radio buttons and check boxes), to transparent when the reset action button is clicked? 

 

Thank you. 

 

 

TOPICS
How to , JavaScript , PDF forms
2.3K
Translate
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
3 ACCEPTED SOLUTIONS
Community Expert ,
Apr 26, 2022 Apr 26, 2022

You must not use the "Reset form" action, you must use the "Run a JavaScript" action with this script:

 

this.resetForm();
for (var i = 0; i < this.numFields; i++) {
var oFld = this.getField(this.getNthFieldName(i));
oFld.fillColor = color.transparent;
}


PDF Acrobatic, InDesigner & Photoshoptographer

View solution in original post

Translate
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 ,
Apr 26, 2022 Apr 26, 2022

Just add a line to restore its color (green in this sample):

 

this.resetForm();
for (var i = 0; i < this.numFields; i++) {
var oFld = this.getField(this.getNthFieldName(i));
oFld.fillColor = color.transparent;
}

event.target.fillColor = color.green;


PDF Acrobatic, InDesigner & Photoshoptographer

View solution in original post

Translate
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 ,
Apr 26, 2022 Apr 26, 2022
LATEST

Or with a custom color:

 

this.resetForm();
for (var i = 0; i < this.numFields; i++) {
var oFld = this.getField(this.getNthFieldName(i));
oFld.fillColor = color.transparent;
}

event.target.fillColor = ["RGB", 255/255, 255/255, 204/255];  // light yellow


PDF Acrobatic, InDesigner & Photoshoptographer

View solution in original post

Translate
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 ,
Apr 26, 2022 Apr 26, 2022

You must not use the "Reset form" action, you must use the "Run a JavaScript" action with this script:

 

this.resetForm();
for (var i = 0; i < this.numFields; i++) {
var oFld = this.getField(this.getNthFieldName(i));
oFld.fillColor = color.transparent;
}


PDF Acrobatic, InDesigner & Photoshoptographer
Translate
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 ,
Apr 26, 2022 Apr 26, 2022

Thank you, this works perfectly. 

 

However, now the fill color of the action button itself also changes to transparent. Anyway I can keep the fill color of the action button? 

Translate
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 ,
Apr 26, 2022 Apr 26, 2022

Just add a line to restore its color (green in this sample):

 

this.resetForm();
for (var i = 0; i < this.numFields; i++) {
var oFld = this.getField(this.getNthFieldName(i));
oFld.fillColor = color.transparent;
}

event.target.fillColor = color.green;


PDF Acrobatic, InDesigner & Photoshoptographer
Translate
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 ,
Apr 26, 2022 Apr 26, 2022
LATEST

Or with a custom color:

 

this.resetForm();
for (var i = 0; i < this.numFields; i++) {
var oFld = this.getField(this.getNthFieldName(i));
oFld.fillColor = color.transparent;
}

event.target.fillColor = ["RGB", 255/255, 255/255, 204/255];  // light yellow


PDF Acrobatic, InDesigner & Photoshoptographer
Translate
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