<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default1.aspx.cs" Inherits="Demo.Default1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" src="http://code.jquery.com/jquery.js"></script>
<script type="text/javascript">
function GetValue()
{
var checkBoxList
= $('#<%=CheckBoxList1.ClientID %>').find('input:checkbox:checked').val();
var radioButtonList
= $('#<%=RadioButtonList1.ClientID %> input:checked').val();
alert("CheckBox
selected value : " + checkBoxList + "\nRadioButton
selected value : " + radioButtonList);
var checkBoxSelectedList
= [];
$.each($('#<%=CheckBoxList1.ClientID %>').find('input:checkbox:checked'), function ()
{
checkBoxSelectedList.push($(this).val());
});
alert("Selected
CheckBox value : " + checkBoxSelectedList.join(",
"));
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:CheckBoxList ID="CheckBoxList1" runat="server">
<asp:ListItem>Male</asp:ListItem>
<asp:ListItem>Female</asp:ListItem>
</asp:CheckBoxList>
<hr />
<asp:RadioButtonList ID="RadioButtonList1" runat="server">
<asp:ListItem>Male</asp:ListItem>
<asp:ListItem>Female</asp:ListItem>
</asp:RadioButtonList>
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="GetValue();" />
</div>
</form>
</body>
</html>
Step 1:- Example
Step 2:- You will get the one one value of both the List
var checkBoxList
= $('#<%=CheckBoxList1.ClientID %>').find('input:checkbox:checked').val();
var radioButtonList
= $('#<%=RadioButtonList1.ClientID %> input:checked').val();
alert("CheckBox
selected value : " + checkBoxList + "\nRadioButton
selected value : " + radioButtonList);
Example:-
Step 3:- You will get the all value of CheckBoxList checked
var checkBoxSelectedList = [];
$.each($('#<%=CheckBoxList1.ClientID %>').find('input:checkbox:checked'), function ()
{
checkBoxSelectedList.push($(this).val());
});
alert("Selected
CheckBox value : " + checkBoxSelectedList.join(",
"));
Example:-
No comments:
Post a Comment