Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML checkbox - allow to check only one checkbox

Tags:

html

checkbox

I have some checkboxes in each row in my table. Each one checkbox has name='myName' because I want to select only one checkbox in each row. But something I'm missing because I'm able to check all of them:

enter image description here

but I want that result:

enter image description here

what am I missing here ?

like image 739
Tony Avatar asked Nov 09 '13 15:11

Tony


People also ask

Does checkbox allow multiple selection?

Checkboxes are objects of a HTML form which behaves like a toggle switch. i.e, a checkbox can be in one of the two states, either checked or unchecked. From a group of checkboxs user can select multiple options.

How do I select only one checkbox in react?

Save this question. Show activity on this post. createElement('div', {className: 'checkbox'}, createElement('label', null, createElement('input', { type: 'checkbox', name: 'tssort', defaultChecked: !

How do I make a check box read only?

A checkbox HTML element doesn't have a "readonly" property. Consequently, the only way to make a checkbox appear to be "readonly" is to disable the control.


2 Answers

The unique name identifier applies to radio buttons:

<input type="radio" />

change your checkboxes to radio and everything should be working

like image 150
silicakes Avatar answered Oct 02 '22 15:10

silicakes


Checkboxes, by design, are meant to be toggled on or off. They are not dependent on other checkboxes, so you can turn as many on and off as you wish.

Radio buttons, however, are designed to only allow one element of a group to be selected at any time.

References:

Checkboxes: MDN Link

Radio Buttons: MDN Link

like image 21
Charlie74 Avatar answered Oct 02 '22 16:10

Charlie74