Let me explain myself i'm doing an Application in VB.net asp.net and I Want to put a CheckBox List instead of Radio Button cause my customer want it square and not round. The Only problem i got is when i check a Checkbox the other one are not unchecked. I'm not sure im clear enough feel free to ask me question.
Asked
Active
Viewed 5,026 times
0
-
A short answer: This is not the default behavior of checkboxes. Radios are for single selections, checks are for multiple. If you'd like to restrict your checkboxes to one selection, you'll have to use Javascript for that. – Matt Grande Mar 21 '13 at 12:51
-
2This is inherently a bad idea. Checkboxes are recognizable as a boolean selection, while circular radio buttons are known for a one-of-many selection. Doing this will just confuse the end-user who expects a boolean choice but finds checkboxes performing a one-of-many choice. – nanofarad Mar 21 '13 at 12:53
-
Like I said I do not have the choice. They want it like this. Matt you have any idea how i could do that i'm really new to JavaScript – William Proulx Mar 21 '13 at 12:55
1 Answers
4
As seen above, this isn't recommended. However if you have to do it, here's how I made it in jQuery:
Create your checkboxes and assign them classes
<input type="checkbox" class="cbr"/>CB 1
<input type="checkbox" class="cbr"/>CB 2
<input type="checkbox" class="cbr"/>CB 3
<input type="checkbox" class="cbr"/>CB 4
<input type="checkbox" class="cbr"/>CB 5
And the jQuery
$(".cbr").click(function() {
$(".cbr").prop("checked", false);
this.checked = true;
});
Here's a demo: http://jsfiddle.net/g2YMs/
Also, if you're creating the checkboxes with ASP.NET controls, you should select them using:
$("#<%=IdOfControl.ClientID%>")
This is, of course, if you decide to go the jQuery way.

Matt Grande
- 11,964
- 6
- 62
- 89

tymeJV
- 103,943
- 14
- 161
- 157
-
Ok this seems good but I've never use Jquery before where do i put it in my code? – William Proulx Mar 21 '13 at 13:45
-
1Here's a nice guide to getting started: http://stackoverflow.com/questions/1458349/installing-jquery -- Good luck with everything! – tymeJV Mar 21 '13 at 13:52
-
OK i've done what they say but the problem is it say that the class cbr is not defined – William Proulx Mar 21 '13 at 14:17
-
1You have to adjust the code to fit your needs. The cbr class is something I defined in each radio button, you can define cbr as your class, or anything you want with the `class` attribute. – tymeJV Mar 21 '13 at 14:21
-
OK I've finnaly found the way to do it thank you very much for your time – William Proulx Mar 21 '13 at 14:54