Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

Checkboxes - Require at least one is checked

Avatar

16-03-2009

I have 4 checkboxes where the user can select any, several or all of them, but I want to require that at least one is checked. Is this posible?



They are named as follows:



Checkbox 1: Lateral

Checkbox 2: Main

Checkbox 3: Inlet

Checkbox 4: Other

Replies

Avatar

Avatar
Validate 1
Level 9
Steve_L_Walker
Level 9

Likes

197 likes

Total Posts

1,435 posts

Correct Reply

212 solutions
Top badges earned
Validate 1
Boost 50
Boost 5
Boost 3
Boost 25
View profile

Avatar
Validate 1
Level 9
Steve_L_Walker
Level 9

Likes

197 likes

Total Posts

1,435 posts

Correct Reply

212 solutions
Top badges earned
Validate 1
Boost 50
Boost 5
Boost 3
Boost 25
View profile
Steve_L_Walker
Level 9

16-03-2009

Kevin,



Given a form with the root 'form1', a subform called 'subform1', and four checkboxes called 'lateral', 'main', 'inlet', and 'other', you could run a script on the change event of each checkbox to compare the current checkbox with all the others. For example,



form1.subform1.lateral::change - (JavaScript, client)



if (form1.subform1.lateral.rawValue == "0") {

if (form1.subform1.main.rawValue == "0" && form1.subform1.inlet.rawValue == "0" && form1.subform1.other.rawValue == "0") {

// xfa.host.messageBox("Please select a minimum of one option.","Options",1);

form1.subform1.other.rawValue = "1";

}

}



form1.subform1.main::change - (JavaScript, client)



if (form1.subform1.main.rawValue == "0") {

if (form1.subform1.lateral.rawValue == "0" && form1.subform1.inlet.rawValue == "0" && form1.subform1.other.rawValue == "0") {

// xfa.host.messageBox("Please select a minimum of one option.","Options",1);

form1.subform1.other.rawValue = "1";

}

}



form1.subform1.inlet::change - (JavaScript, client)



if (form1.subform1.inlet.rawValue == "0") {

if (form1.subform1.lateral.rawValue == "0" && form1.subform1.main.rawValue == "0" && form1.subform1.other.rawValue == "0") {

// xfa.host.messageBox("Please select a minimum of one option.","Options",1);

form1.subform1.other.rawValue = "1";

}

}



form1.subform1.other::change - (JavaScript, client)



if (form1.subform1.other.rawValue == "0") {

if (form1.subform1.lateral.rawValue == "0" && form1.subform1.main.rawValue == "0" && form1.subform1.inlet.rawValue == "0") {

// xfa.host.messageBox("Please select a minimum of one option.","Options",1);

form1.subform1.other.rawValue = "1";

}

}



This will force 'other' to be selected. Of course, if a user doesn't click any checkbox than you will have to put additional logic to validate prior to printing, saving, submitting, or whatever action signifies form fill completion.



Steve

Avatar

17-03-2009

I'd ask Paul Guerette for one of his fake e-mail button forms.



There in the click event, of the fake-mail-button, java script, put the following:



if (form1.subform1.lateral.rawValue == "0" && form1.subform1.other.rawValue == "0" && form1.subform1.main.rawValue == "0" && form1.subform1.inlet.rawValue == "0")

{xfa.host.messageBox("Please select at least one checkbox.");}



The user shouldn't be able to send it, without less than one checkbox activated. Of course you can set ur errormessage as you please and add more scripts f.ex. to make the boarders of the checkboxes red etc..

Avatar

Avatar
Boost 500
Level 10
pguerett
Level 10

Likes

611 likes

Total Posts

7,689 posts

Correct Reply

692 solutions
Top badges earned
Boost 500
Boost 50
Boost 5
Boost 3
Boost 250
View profile

Avatar
Boost 500
Level 10
pguerett
Level 10

Likes

611 likes

Total Posts

7,689 posts

Correct Reply

692 solutions
Top badges earned
Boost 500
Boost 50
Boost 5
Boost 3
Boost 250
View profile
pguerett
Level 10

17-03-2009

Both of the mentioned methods will work but there is a better way. One of my colleages writes a blog about XFA and forms. Here is the URL:



http://blogs.adobe.com/formfeed



This is an excellent blog and deals with advanced topics (sometimes too advanced). Anyways in the topic of validations he wrote one about exclusion groups ...I suggest that you read that one ....he has a sample in there that does exactly what you are asking.

Avatar

17-03-2009

Thanks everyone for the input and assistance. I ended up using Lisa's method and added a xfa.event.cancelAction.



It seems to work well.



if (topmostSubform.Page1.Lateral.rawValue == "0" && topmostSubform.Page1.Main.rawValue == "0" && topmostSubform.Page1.DrainInlet.rawValue == "0" && topmostSubform.Page1.Other.rawValue == "0")

{xfa.host.messageBox("Please select at least one checkbox for Type."); xfa.event.cancelAction = 1;}