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(); } });
Comments
Post a Comment