Reputation: 185
How i can code the functionality of checkbox like radiobutton,below is mine quick code but it's seems not so perfect.
<asp:checkbox id="chkA" runat="server" onClick="SetCheck(this)"/>
<asp:checkbox id="chkB" runat="server" onClick="SetCheck(this)"/>
<Javascript>
function SetCheck(chk)
{
Switch(chk.id)
{
case "chkA" :
chkB.checked=false;
break;
Case "chkB" :
chkA.checked=false;
break;
}
}
</Javascript>
Upvotes: 0
Views: 471
Reputation: 207511
HTML
<input type="checkbox" id="a" onclick="flip(this)" />
<input type="checkbox" id="b" onclick="flip(this)" />
JavaScript: Flips to other
function flip(cb){
var other = cb.id==="a" ? "b" : "a";
document.getElementById(other).checked = !cb.checked;
}
JavaScript" Allows to be deselected
function flip(cb){
if (cb.checked) {
var other = cb.id==="a" ? "b" : "a";
document.getElementById(other).checked = false;
}
}
Upvotes: 1