Skip to main content
Participant
October 13, 2020
Question

Tick boxes - at least one has to be ticked

  • October 13, 2020
  • 3 replies
  • 1184 views

Hi Community, 

 

I have the following scenario in a PDF form. 

 

Under a question, I have three tick boxes, at least one needs to be ticked, but also either two or all three can also be ticked. 

Can someone please advise the appropriate Javascript to use?

 

Thanks Claire 

 

 

 

This topic has been closed for replies.

3 replies

Nesa Nurani
Community Expert
Community Expert
October 13, 2020

You can make checkboxes required but it won't do you any good since submit check for empty value
and checkboxes are never empty.What you need is make hidden text field and use script in it, when no checkboxes are tick
field will be required and if any checkbox is tick field is not required.
You can try using this script as custom calculation script of hidden text field, and change field names if needed.
var c1 = this.getField("Check Box2").value;
var c2 = this.getField("Check Box3").value;
var c3 = this.getField("Check Box4").value;
if(c1 != "Off" || c2 != "Off" || c3 != "Off"){
event.value = "Required";}
else event.value = "";
if(event.value == ""){
event.target.required = true;}
else event.target.required = false;

try67
Community Expert
Community Expert
October 13, 2020

This will work, but the problem is it will be unclear to the user what fields they are missing when trying to submit the form.

It's better to use a script for the Submit button in which you control that either one of those check-boxes is ticked (as well as all other required fields), and if so, submit the file. If they're not you display an error message to the user, explaining what the issue is.

Inspiring
October 13, 2020

Do you want to make checkboxes required if you use submit or you just want that user need to check one of the boxes?

If it's latter then you need to describe us a scenario how you are using boxes?

Participant
October 13, 2020

Thanks for responding. So yes, to allow the user to submit the form they need to check at least one of the checkboxes as a response to the question. But they can also check multiple boxes. 

 

try67
Community Expert
Community Expert
October 13, 2020

Just give each field a unique name and they'll work independently of each other.

When you say that "at least one fields needs to be checked", what do you mean by that, exactly? What should happen if no fields are checked?

Participant
October 13, 2020

Thanks for responding. So they need to select at least one of the below to able to "submit" the application. No fields are allowed to be left unchecked.