html - Limit number of checkboxes to be selected, jQuery -


a simpler version of question has been posted, i'm having difficulty.

say have 5 checkboxes:

  • none
  • apple
  • banana
  • orange
  • pear

the user allowed select 2 checkboxes, if "none" chosen, can select one.

is possible @ all?

try play example:

var checked = [], $check = $('.check').change(function() {     if (this.value == -1 && this.checked) {         $check.not(this).prop('disabled', true).prop('checked', false);         checked = [];     }     else {         $check.prop('disabled', false);         checked.push(this);         checked = $(checked)         checked.prop('checked', false).slice(-2).prop('checked', true);     } }); 

http://jsfiddle.net/q7dve/


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

javascript - Clean way to programmatically use CSS transitions from JS? -

android - send complex objects as post php java -