Description:
Code:
In this example we explain that how
to call RadioButtonList on Change event using JavaScript. Or how to call RadioButtonList
SelectedIndexChanged event in JavaScript. Or how to implement the RadioButtonList
SelectedIndexChanged event using JavaScript.
As we know that the
SelectedIndexChanged Event in asp.net is a Server Side event so the question is
that how to call that event at client side using JavaScript.
So here we demonstrate that how to
call or implement the selectedchangedevent of the RadioButtonList using JavaScript at client side.
<%@
Page Language="C#" AutoEventWireup="true" CodeBehind="test.aspx.cs" Inherits="SWS.Dashboard.test" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<script
type="text/javascript">
window.onload = function () {
var
rbl = document.getElementById("<%=rdbGameList.ClientID
%>");
var
radio = rbl.getElementsByTagName("INPUT");
for
(var i = 0; i < radio.length; i++) {
radio[i].onchange = function () {
var
radio = this;
var
label = radio.parentNode.getElementsByTagName("LABEL")[0];
alert("SelectedText: " + label.innerHTML
+ "\nSelectedValue:
" + radio.value);
};
}
};
</script>
<title>Implement ASP.Net RadioButtonList
SelectedIndexChanged event in jQuery</title>
</head>
<body>
<form
id="form1"
runat="server">
<div>
<h1>
Select Your favourite Games ?
</h1>
<hr />
<br />
<asp:RadioButtonList ID="rdbGameList" runat="server">
<asp:ListItem Text="Cricket" Value="1"></asp:ListItem>
<asp:ListItem Text="Tennis" Value="2"></asp:ListItem>
<asp:ListItem Text="FootBall" Value="3"></asp:ListItem>
<asp:ListItem Text="VoleyBall" Value="4"></asp:ListItem>
</asp:RadioButtonList>
</div>
</form>
</body>
</html>
0 comments:
Post a Comment