Copy link to clipboard
Copied
I have Yes/No checkboxes on my form that require one or the other to be checked. I would like for these fields to be highlighted yellow if both are left unchecked. How can I get this accomplished? I was able to run a javascript in other text fields to have the field highlighted if left blank, but, it won't work for checkboxes. Thanks!
Since they are mutually exclusive, you need to access their individual widgets, first checkbox has widget 0 and second 1, like this:
pg2_Q1.Check1.0
pg2_Q1.Check1.1
Run this script in both checkboxes as Mouse UP action:
var c1 = this.getField("pg2_Q1.Check1.0");
var c2 = this.getField("pg2_Q1.Check1.1");
c1.fillColor = c1.value == "Yes" ? color.white : color.yellow;
c2.fillColor = c2.value == "No" ? color.white : color.yellow;
Copy link to clipboard
Copied
What is the name of Checkboxes?
What script did you try to use and where?
Copy link to clipboard
Copied
For one particular question, box checkboxes (Yes and No) are named pg2_Q1.Check1
I used the script below in the checkbox properties Action setup:
event.target.fillColor = (event.value=="") ? color.yellow : color.transparent;
As I mentioned, this script works for my text fields, but not the checkbox fields.
Thanks!
Copy link to clipboard
Copied
Since they are mutually exclusive, you need to access their individual widgets, first checkbox has widget 0 and second 1, like this:
pg2_Q1.Check1.0
pg2_Q1.Check1.1
Run this script in both checkboxes as Mouse UP action:
var c1 = this.getField("pg2_Q1.Check1.0");
var c2 = this.getField("pg2_Q1.Check1.1");
c1.fillColor = c1.value == "Yes" ? color.white : color.yellow;
c2.fillColor = c2.value == "No" ? color.white : color.yellow;
Copy link to clipboard
Copied
Thanks for this information! A couple of questions:
1) What do you mean by accessing their individual widgets? Do I just rename each one?
2) How do I get the checkbox to highlight/unhighlight each time the checkbox is checked/unchecked? It will highlight when blank, but, not unhighlights once checked.
Copy link to clipboard
Copied
1. Because they share the same name, if you don't access their widget, the script will apply to all checkboxes.
The first field that is created is widget 0 second field is widget 1...etc. If you look at my script, you will see that I added .0 and .1 to the checkbox name, that means the script will apply to that checkbox only.
2. If you did everything as I explained, the checkbox should highlight/unhighlight when checked/unchecked.
Make sure your checkboxes have export value of "Yes" and "No".
Copy link to clipboard
Copied
Thanks for explaining the widgets. I've entered the code exactly as you've suggested. It is working for the Yes checkbox now, but, not working for the No checkbox. Any other suggestions?
Copy link to clipboard
Copied
Can you share your file, so I can take a look at it?