javascript - jquery choosing one checbox between two checboxes -
i have 2 checkboxes. want algorithm happen: if check checkbox1 want checkbox 2 uncheck, if check checkbox2 want checkbox1 unchecked. therefore, need select 1 checkbox only. , want in jquery. thank you..
html
<input type="checkbox" name="checkme" id="cc1">check me1</input> <input type="checkbox" name="checkme" id="cc2">check me2</input>
javascript
$('#cc1').change(function(){ var c = this.checked ? $('#cc1').prop('checked', true) : $('#cc2').prop('checked', false); }); $('#cc2').change(function(){ var c = this.checked ? $('#cc2').prop('checked', true) : $('#cc1').prop('checked', false); });
$('#cc1').change(function(){ $('#cc2').prop('checked', !$(this).prop('checked')); }); $('#cc2').change(function(){ $('#cc1').prop('checked', !$(this).prop('checked')); });
maybe radio buttons better fit such case.
Comments
Post a Comment