Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hai i need a function in javascript for check/uncheck of radiobutton onClick .. anyone help me....


HTML
<p class="quesposition">@questionNo ) @Html.DisplayFor(modelItem => item.Question)</p>
           <div class="rbtnposition">
               @Html.RadioButton("radio", "1", new { onclick = "rbtnCheck()" }) <span>@Html.DisplayFor(modelItem => item.Choice1)</span><br><br>
               @Html.RadioButton("radio", "2", new { onclick = "rbtnCheck()" }) <span>@Html.DisplayFor(modelItem => item.Choice2)</span><br><br>
               @Html.RadioButton("radio", "3", new { onclick = "rbtnCheck()" }) <span>@Html.DisplayFor(modelItem => item.Choice3)</span><br><br>
               @Html.RadioButton("radio", "4", new { onclick = "rbtnCheck()" }) <span>@Html.DisplayFor(modelItem => item.Choice4)</span><br><br>
           </div>
Posted
Comments
VICK 18-Dec-15 1:15am    
Do assign a class to all radio buttons.. and write a function according to that.. and in that check using .is(':checked') about the check/uncheck.

If you need further help .. Please explain your scenario a bit more.
ajeeshsathyan 18-Dec-15 1:36am    
i have the code but first time click on radiobutton is checked second time click not unckeck but third time click unchecked ..


function rbtnCheck() {
var allRadios = document.getElementsByName('radio');
var booRadio;
var x = 0;
for (x = 0; x < allRadios.length; x++) {
allRadios[x].onclick = function () {
if (booRadio == this) {
this.checked = false;
booRadio = null;
} else {
booRadio = this;
}
};
}
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900