-1

I have 3 checkboxes and how I can disable remaining two checkboxes on selecting one checkbox My code is

model
public bool checkbox1{get; set;}
public bool checkbox2{get; set;}
public bool checkbox3{get; set;}

View

@Html.CheckBoxFor(m=>m.checkbox1)
@Html.CheckBoxFor(m=>m.checkbox2)
@Html.CheckBoxFor(m=>m.checkbox3)

When I select checkbox 1, remaining 2 checkboxes should be disabled and vice versa. I am new to programming. can u help me out using javascript

win2
  • 11
  • 4
  • You should try a few things and if you can't figure it out, post your attempts along with what happened instead of what you wanted. – Brian White Mar 20 '15 at 06:32
  • Handle the jquery [.change()](http://api.jquery.com/change/) event, and use jquery [.prop()](http://api.jquery.com/prop/) to disable all checkboxes except the selected one. Note: disabling a check box means in wont post back so the other 2 properties will be `false` –  Mar 20 '15 at 06:32
  • Please review the [help section](http://stackoverflow.com/help) to understand what is an acceptable question. SO is not a code writing service. –  Mar 20 '15 at 06:45

1 Answers1

0

Something like this? http://jsfiddle.net/6tdhm4p2/1/

$('.checkbox').change(function(){
    $(this).is(':checked')?$(this).siblings('.checkbox').prop('disabled',true):"";
});
Manoz
  • 6,507
  • 13
  • 68
  • 114