c# - how to select only one check box with JQuery -


<div class="form-group"> @html.checkboxfor(x => x.clientaccountishospitality, new { @type = "checkbox" }) @html.labelfor(x => x.clientaccountishospitality) </div> <div class="form-group"> @html.checkboxfor(x => x.clientaccountisretail, new { @type = "checkbox" }) @html.labelfor(x => x.clientaccountisretail) </div>  <script type="text/javascript" language="javascript">          $(document).ready(function () {             $("input[type='checkbox']").change(function () {                 $(this).closest(".checkboxcontainer").find("input[type='checkbox']").not(this).prop("checked", false);                 $(this).prop("checked", true);             });         });         </script> 

i hoping when user selects check box, other check box de-select, if selected. problem code user can select check box cant de-select again. either selecting check box or trying un select selected box

note have used checkboxes through out site , stick this. not want radio button. thaks

$(':checkbox').click(function(e){     if($(this).is(':checked')){         $(':checked').prop('checked', false);         $(this).prop('checked', true);      }     else{         e.preventdefault();     } }); 

example


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -