-2

I had Check boxes as below:

input name="rec type" type="check box" value="1" one

input name="rec type" type="check box" value="2" Two

input name="rec type" type="check box" value="3" Three

input name="rec type" type="check box" value="4" Four

Now if i checked on any one check box,i have to get all check box values as array and if user checks on check box one,i need to disable two and four Check boxes.

Any inputs on how to do this?

Thanks in Advance..

Sai Avinash
  • 4,683
  • 17
  • 58
  • 96

3 Answers3

0

add a class class="ckbox"to your all input box and try this :

<input name="rec type" type="checkbox" value="1" class="ckbox" />

Jquery

 <script type="text/javascript">
    $(document).ready(function () {
        $('.ckbox').click(function () {
            $('.ckbox').prop('checked', $(this).is(":checked"));
        });
    });

</script>
Mohammad Arshad Alam
  • 9,694
  • 6
  • 38
  • 61
0

All checkbox values in an array

var values = $("[name='rectype']").map(function(){return this.value}).get();

To disable, use onchange and check if the first checkbox is checked

var isOneChecked = $("[name='rectype'][value='1']").is(":checked");

than you can disable them using prop

$("[name='rectype'][value='4']").prop("disabled", isOneChecked);
epascarello
  • 204,599
  • 20
  • 195
  • 236
0

Try this instead.

HTML:

<input type="checkbox" value="1"/>one
<input type="checkbox" class="odd" value="2"/>two
<input type="checkbox" value="3"/>three
<input type="checkbox" class="odd" value="4"/>four

JQuery:

$('input[type="checkbox"]').change(function(){
   var myArr = []; 
   if($(this).val() == "1"){
      $('.odd').prop('disabled',!$('.odd').attr('disabled'));
   }

   $('input[type="checkbox"]:checked').each(function(){
     myArr.push($(this).val());
   }); 
   alert(myArr);
});

JSFiddle

Navin
  • 594
  • 2
  • 11