How to change button caption color in pdf by javascript
Copy link to clipboard
Copied
Hi There,
I want to toggle the button color of a pdf form along the with the caption/label color of each button. For this, I have written this code:
for(i=1;i<bn+1;i++){
var b = "btn"+i;
var f = this.getField(b);
if (color.equal(f.fillColor, color.white)){
f.textColor = color.white;
f.fillColor = color.red;
}else{
if(bn==1){
f.fillColor = color.white;
f.textColor = color.black;
}else{
f.textColor = color.black;
}
}
Everything is working well except for the color of the Caption/Label. It is black in default and remains black even the fill color is changing. How to change the Caption/Label color to white too?
Copy link to clipboard
Copied
What is the value of variable "bn" ?
Copy link to clipboard
Copied
It is the current button number. Let's say I have five buttons which names are btn1, btn2, btn3, btn4 & btn5 respectively.
Copy link to clipboard
Copied
Where does you set or change the variable "bn" ?
Copy link to clipboard
Copied
Actually this function will be put on Document Label (let's say function name is bcolor(bn) and in every button, an action will be set. As for example in btn3, the javascript action will be:
bcolor(3)
where 3 is the current button number and 5 is the highest button number.
Copy link to clipboard
Copied
For this sample the fill color will be changed from white to red.
What happens when you use bcolor(1)?
Copy link to clipboard
Copied
So you are saying that when the fill color is changing to red, that the text color does not change to black?
You're code looks correct and "textColor" is the right property. I would suggest putting "console.println()" statements into the code so you can see which code blocks are being run with which button numbers.
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
No, I want when the fill color will be red, at that time text color will be white so that text can be seen clearly.

