Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

HTML

how to select one checkbox at same time ?

hey i faced a problem in checkbox selection i want to select one checkbox in same time

  <div class="choices">
    <input type = "checkbox" id="A" name="answer" class="choice0" value=""><label id="choice0" for="A">option1</label><br/>
    <input type = "checkbox" id="B" name="answer" class="choice1" value=""><label id="choice1" for="B">option2</label><br/>
    <input type = "checkbox" id="C" name="answer" class="choice2" value=""><label id="choice2" for="C">option3</label><br/>
    <input type = "checkbox" id="D" name="answer" class="choice3" value=""><label id="choice3" for="D">option4</label><br/>
  </div>

as a choice for questions of quiz

Brent Suggs
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Brent Suggs
Front End Web Development Techdegree Graduate 21,343 Points

sorry, I think you misunderstood. Why are you wanting to select only one of them? For styling..? or are you trying to do the sytle for when one is checked/selected?

2 Answers

Jake Lundberg
Jake Lundberg
13,965 Points

Are you required to use checkboxes? If not, you should use radio buttons instead. This would allow you to group buttons together, but only allow for one to be selected at a time.

Steven Parker
Steven Parker
229,578 Points

I agree with using the radio buttons. Unless...

You may just WANT checkboxes, in which case you could give them behavior similar to radio buttons using a little JavaScript.

Your quiz might also have some questions where there might be more than one correct answer, and all of them should be selected.