Expand my Community achievements bar.

How to modify format of a button when you click it?

Avatar

Former Community Member
I am very new to Designer. I am designing a dynamic, interactive form with a subform that adds/removes a "Comments" section when you click a button. The caption on the button changes to/from "Add Comments" / "Clear Comments" when you click the button and the "Comments" section is added/removed. I would like to have the background color of the button and the color of the text change as well.



I am guessing that I would have to include something in the scripting but I am not a Java scripting expert. I just copied the scripting for the adding and removing of the "Comments" section from one of the sample forms in the library that accompanied Designer. I am fairly adept and intuitive but I need some help getting started. I would like to have blue button/white font & red button/black font.



Any help would be greatly appreciated.



Thanks,

Dean
3 Replies

Avatar

Former Community Member
Hello W. Dean,



I hope this helps you.




On Click Event (button)






// I establish the state of the button depending on the text that it contains

// You can use the button's background color or its text color too.


var buttonText = xfa.resolveNode("this.caption.value.#text").value;




// Check the condition.


if(buttonText == "ADD COMMENT"){




   // Changing the caption of the button's text.


   xfa.resolveNode("this.caption.value.#text").value = "CLEAR COMMENT";




   // Changing the text color to black.


   this.caption.font.fill.color.value = "0,0,0";




   // Changing the button's background color to red.


   this.fillColor = "255,0,0";



}else{



   xfa.resolveNode("this.caption.value.#text").value = "ADD COMMENT";



   this.caption.font.fill.color.value = "255,255,255";

// white




   this.fillColor = "20,120,220";
//blue


}




Good luck,

Dan

Avatar

Former Community Member
Thanks Dan. That worked. Can you recommend a good book for Java script to use in conjunction with Designer that is relatively easy for the non-programmer to understand?

Avatar

Former Community Member
Ummm I never have bought any book of JavaScript. I have learned about it reading the internet tutorials and examples (it's all for free).



JavaScript language is very simple and intuitive. In a few weeks you will understand it perfectly.




Regards,

Dan