Search This Blog

Thursday, January 27, 2011

RadiobuttonList-Selected Index

<script type="text/javascript">
function getSelectedIndex() {
var radioButtons = document.getElementsByName("RadioButtonList1");
for (var x = 0; x < radioButtons.length; x ++) {
if (radioButtons[x].checked)
{
document.getElementById("spnmsg").innerHTML = "selected " +radioButtons[x].value;
// alert(radioButtons[x].value);
}
}
}
</script>

-------------------------------Example-----------------------
<span id="spnmsg"></span>
<asp:RadioButtonList ID="RadioButtonList1" onclick="getSelectedIndex()" runat="server">
<asp:ListItem Value="0" Text="Item0"></asp:ListItem>
<asp:ListItem Value="1" Text="Item1"></asp:ListItem>
<asp:ListItem Value="2" Text="Item2"></asp:ListItem>
</asp:RadioButtonList>

No comments:

Post a Comment