admin管理员组文章数量:1323157
I have a RadioButtonList control in a web user control and it is loaded in a place holder of web page. The radio button list items will be loaded dynamically and the user can select any item.
As per the radio button behavior, we want to select another item to deselect already selected item. But I want to deselect an item if the user clicked on same item itself if it was already checked.
Also I have to do it using javascript not Server side code.
I have a RadioButtonList control in a web user control and it is loaded in a place holder of web page. The radio button list items will be loaded dynamically and the user can select any item.
As per the radio button behavior, we want to select another item to deselect already selected item. But I want to deselect an item if the user clicked on same item itself if it was already checked.
Also I have to do it using javascript not Server side code.
Share asked Dec 13, 2012 at 13:21 JobiJobi 1,1225 gold badges26 silver badges38 bronze badges 1- You've received some great answers in the past. How about you mark some of them as answered? It'll help you get better answers in the future. – Niklas Commented Dec 13, 2012 at 13:23
2 Answers
Reset to default 5Add this javascript function in <Head>
tag.
<script type="text/javascript">
function clearRadioButtonList() {
var elementRef = document.getElementById('<%= yourRadioButtonListID.ClientID %>');
var inputElementArray = elementRef.getElementsByTagName('input');
for (var i = 0; i < inputElementArray.length; i++) {
var inputElement = inputElementArray[i];
inputElement.checked = false;
}
return false;
}
</script>
When you dynamically add listitem, add onclick attribute to listitem:
myListItem.Attributes.Add("onclick", "clearRadioButtonList");
Don't forget to replace "yourRadioButtonListID" in javascript function. This will uncheck the clicked radio button if it is checked.
Thanks.
Much easier with jquery
<script type="text/javascript">
$(document).ready(function () {
$('#btnTest').click(function () {
var radiolist = $('#RadioButtonList1').find('input:radio');
radiolist.removeAttr('checked');
});
});
</script>
本文标签: aspnetUncheck dynamically radiobuttonlist control using javascriptStack Overflow
版权声明:本文标题:asp.net - Uncheck dynamically radiobuttonlist control using javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742143724a2422695.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论