Home > ASP.Net, Jquery > Get Selected Value and Text from CheckBoxList Using JQuery

Get Selected Value and Text from CheckBoxList Using JQuery


Dear all,

try this example to Get Selected Value and Text from CheckBoxList Using JQuery


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!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 runat="server">
<title></title>
<script src="scripts/jquery-1.4.3.min.js" type="text/javascript"></script>
<script type="text/javascript">
function btnShow_onclick() {
$("#spnLabels").text("");
$("#spnValues").text("");
var labels = "";
var values = "";
$("#<%= CheckBoxList1.ClientID %> input:checkbox:checked").each(function() {
var label = $('label[for=' + this.id + ']').html();
var value = $(this).parent().attr('hiddenValue');
labels += label + ", ";
values += value + ", ";
});
labels = labels.substring(0, labels.length - 2);
values = values.substring(0, values.length - 2);
$("#spnLabels").text(labels);
$("#spnValues").text(values);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:CheckBoxList ID="CheckBoxList1" runat="server">
<asp:ListItem Text="Google" Value="1" />
<asp:ListItem Text="Yahoo" Value="2" />
<asp:ListItem Text="Bing" Value="3" />
</asp:CheckBoxList>
<br />
<input id="btnShow" type="button" value="Show Selected Items" onclick="return btnShow_onclick()" />
<br />
<br />
<span id="spnLabels"></span>
<br />
<br />
<span id="spnValues"></span>
<br />
</form>
</body>
</html>

Hope this helps

Good Luck.

Advertisements
Categories: ASP.Net, Jquery
  1. June 7, 2014 at 11:47 am

    Reblogged this on modyrefay.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: