svk
svk

Reputation: 4553

Can I select only one checkbox out of multiple checkboxes using jquery?

I need to allow the user to check only one checkbox out of more than five checkboxes. The checkboxes are having the same name and different values. I need to store these values and retrieve from database. Does Jquery support this feature? I am a newbie...

Upvotes: 0

Views: 4757

Answers (3)

Andreas Köberle
Andreas Köberle

Reputation: 110922

When you dont wont radio buttons here is a jquery solution:

var checkboxes = $(':checkbox.myCheckboxGroup');
checkboxes.click(function(){
  var self = this;
  checkboxes.each(function(){
    if(this!=self) this.checked = ''
  })
})

Upvotes: 0

Natrium
Natrium

Reputation: 31174

use radiobuttons.

http://www.w3schools.com/html/html_forms.asp --> scroll down to Radio Buttons

Upvotes: 1

rahul
rahul

Reputation: 187050

Better to use radio buttons in this case. They are meant to serve this purpose. Selecting only an item from this case.

If checkbox is a strict requirement then you can do this with jQuery. You have to unselect all the checboxes first and then check the one which is clicked.

Upvotes: 2

Related Questions