0

I want to make only one checkbox of a group of checkboxes mandatory for the user to check without using JavaScript. I have the following (quite simple) code:

<input type="checkbox" class="checkbox_condition" name="checkboxGroupName" id="first" required>
<input type="checkbox" class="checkbox_condition" name="checkboxGroupName" id="first" required>

I want to compel visitor to select one checkbox from the group. How can I do that without JavaScript? I would appreciate any recommendations.

1
  • A little more code for context may help Commented Jul 29, 2015 at 20:01

1 Answer 1

1

Switch your checkbox to radio - radio buttons have the built in function you are looking for, in your css you can make the radio button look like a check box. see my fiddle https://jsfiddle.net/pcvwwjoe/2/

<input type="radio" class="checkbox_condition" name="checkboxGroupName" id="first" required>
  <input type="radio" class="checkbox_condition" name="checkboxGroupName" id="first"> 

also, notice that since both radio buttons have the same name, you only need to use required once since they are all grouped together.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.