How to get a required check box field to highlight if left blank?

New Here ,
Aug 26, 2022 Aug 26, 2022

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!

TOPICS
JavaScript , PDF forms

Views

62

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Aug 26, 2022 Aug 26, 2022

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;

 

Likes

Translate

Translate
Community Expert ,
Aug 26, 2022 Aug 26, 2022

Copy link to clipboard

Copied

What is the name of Checkboxes?

What script did you try to use and where?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 26, 2022 Aug 26, 2022

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!

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 26, 2022 Aug 26, 2022

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;

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 29, 2022 Aug 29, 2022

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.

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 29, 2022 Aug 29, 2022

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".

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 29, 2022 Aug 29, 2022

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?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 29, 2022 Aug 29, 2022

Copy link to clipboard

Copied

LATEST

Can you share your file, so I can take a look at it?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

Make content for your business needs with Adobe Express.

Get started easily with free templates: