Skip to main content
Participant
March 27, 2023
Question

Clicking of a checkbox is changing the colour of another checkbox - javascript

  • March 27, 2023
  • 1 reply
  • 281 views

Hello,

 

Please could you help me with the following - im making a service report with lots of check boxes. The plan was to cycle through the following

 

"Green tick" OK

"Orange circle" Warning

"Red cross" Fault

 "White blank square" N/A

 

Thanks to other posters and experts who have responded ive done some research around the forums and got it to work for one checkbox. However if i apply the javascript to another button on the same form (different name), the colour of the 1st checkbox goes back to transparent and the second box changes to the next colour. If i click between the buttons the colour cycles through on each checkbox in turn but is not stored to the checkbox 

 

Its almost like the code is applicable to each mouse button click rather than stored and linked to the checkbox. This is the code im using - the first part is dealing with the colour, the second part is dealing with the checkbox. The checkbox part works fine and stores correctly to every checkbox:

 

if (color.equal(color.green, event.target.fillColor)){event.target.fillColor = color.yellow;}

 

else if
(color.equal(color.yellow,event.target.fillColor)){event.target.fillColor = color.red;}

 

else if
(color.equal(color.red,event.target.fillColor)){event.target.fillColor = color.white;}


else event.target.fillColor = color.green;

 

if (event.target.value!="Off") {
event.target.style=style.ch;
event.target.exportValues=["Check"];
event.target.value=event.target.exportValues;

 

} else if (event.target.value=="Off" && event.target.exportValues=="Check") {
event.target.style=style.ci;
event.target.exportValues=["Circle"];
event.target.value=event.target.exportValues;

 

} else if (event.target.value=="Off" && event.target.exportValues=="Circle") {
event.target.style=style.cr;
event.target.exportValues=["Cross"];
event.target.value=event.target.exportValues;

 

} else event.target.exportValues=["Other"];

 

I wonder if there was a different way this could be written - for example:

 

If checkbox = check, set colour to green

If checkbox = circle, set colour to yellow, etc 

 

Would very much appreciate any advise

 

Attached a test file

 

Dave.

 

 

This topic has been closed for replies.

1 reply

Participant
March 27, 2023

Solved - ive decided to do away with the checkbox aspect and use it as a button. All the buttons work independantly.