Skip to main content
Participant
Apr 27, 2020 8:29 PM UTC
Question

Mudar de cor ao selecionar um botão

É possivel criar um formulário onde eu possa atribuir uma área que mude de cor ao clicar?

Séria possivel ter uma lista de cores que eu possa escolher para aplicar naquela área?

This topic is closed to new replies. Start a new post to keep the conversation going.

3 replies

try67
Community Expert
Community Expert
Apr 27, 2020 9:28 PM UTC

Sure, you can do that with a button field. Do you mean that you want it to change from one color to another each time you click it, like a "traffic light" (red to yellow to green to red, etc.)?

Translate
erikkasAuthor
Participant
Apr 28, 2020 12:08 PM UTC

Yes, that's right. How can I do that?
I looked for tutorials on the Internet but I couldn't find them.

Translate
try67
Community Expert
Community Expert
Apr 28, 2020 12:59 PM UTC

Sure, here's an example. Create a button with a red (RGB 1,0,0) fill color and then set the following as its MouseUp JavaScript code:

 

var colors = [color.red, color.yellow, color.green];

for (var i=0; i<colors.length; i++) {
	if (color.equal(event.target.fillColor, colors[i])) {
		event.target.fillColor = (i==colors.length-1) ? colors[0] : colors[i+1];
		break;
	}
}

Each time you click it it will switch to the next color in the colors array, which can be as long as you wish.

Translate