Fresher says:
$(
function
() {
$(
"[id*=btnAgregar]"
).click(
function
() {
var
checked_checkboxes = $(
"[id*=projectchk] input:checked"
);
var
message =
""
;
checked_checkboxes.each(
function
() {
var
text = $(
this
).closest(
"td"
).find(
"label"
).html();
message +=
"Text: "
+ text;
message +=
"\n"
;
});
alert(message);
return
false
;
});
});
Replace the above with the below.
$(function () {
$("[id*=btnAgregar]").click(function () {
var checked_checkboxes = $("[id*=projectchk] input:checked");
var message = "";
checked_checkboxes.each(function () {
var text = $(this).closest("span").find("label").html();
message += "Text: " + text;
message += "\n";
});
alert(message);
return false;
});
});
Or
$("[id*=btnAgregar]").click(function () {
var checked_checkboxes = $("[id*=projectchk] input:checked");
var message = "";
checked_checkboxes.each(function () {
var text = $(this).parent().find("label").html();
message += "Text: " + text;
message += "\n";
});
alert(message);
return false;
});
Both will work in your case.
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$("[id*=btnAgregar]").click(function () {
var checked_checkboxes = $("[id*=projectchk] input:checked");
var message = "";
checked_checkboxes.each(function () {
var text = $(this).closest("span").find("label").html();
message += "Text: " + text;
message += "\n";
});
alert(message);
return false;
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table cellspacing="0" border="0" id="ctl00_cphGlobalContent_FormView1" style="border-collapse: collapse;">
<tbody>
<tr>
<td colspan="2">
<div class="form-check form-check-inline" id="projectchk">
<span class="form-check-input">
<input id="ctl00_cphGlobalContent_FormView1_Repeater1_ctl01_CategoryID" type="checkbox"
name="ctl00$cphGlobalContent$FormView1$Repeater1$ctl01$CategoryID"><label for="ctl00_cphGlobalContent_FormView1_Repeater1_ctl01_CategoryID">170449</label></span>
<span class="form-check-input">
<input id="ctl00_cphGlobalContent_FormView1_Repeater1_ctl02_CategoryID" type="checkbox"
name="ctl00$cphGlobalContent$FormView1$Repeater1$ctl02$CategoryID"><label for="ctl00_cphGlobalContent_FormView1_Repeater1_ctl02_CategoryID">170450</label></span>
<span class="form-check-input">
<input id="ctl00_cphGlobalContent_FormView1_Repeater1_ctl03_CategoryID" type="checkbox"
name="ctl00$cphGlobalContent$FormView1$Repeater1$ctl03$CategoryID"><label for="ctl00_cphGlobalContent_FormView1_Repeater1_ctl03_CategoryID">170451</label></span>
<span class="form-check-input">
<input id="ctl00_cphGlobalContent_FormView1_Repeater1_ctl04_CategoryID" type="checkbox"
name="ctl00$cphGlobalContent$FormView1$Repeater1$ctl04$CategoryID"><label for="ctl00_cphGlobalContent_FormView1_Repeater1_ctl04_CategoryID">170452</label></span>
<span class="form-check-input">
<input id="ctl00_cphGlobalContent_FormView1_Repeater1_ctl05_CategoryID" type="checkbox"
name="ctl00$cphGlobalContent$FormView1$Repeater1$ctl05$CategoryID"><label for="ctl00_cphGlobalContent_FormView1_Repeater1_ctl05_CategoryID">170453</label></span>
<span class="form-check-input">
<input id="ctl00_cphGlobalContent_FormView1_Repeater1_ctl06_CategoryID" type="checkbox"
name="ctl00$cphGlobalContent$FormView1$Repeater1$ctl06$CategoryID"><label for="ctl00_cphGlobalContent_FormView1_Repeater1_ctl06_CategoryID">170454</label></span>
<span class="form-check-input">
<input id="ctl00_cphGlobalContent_FormView1_Repeater1_ctl07_CategoryID" type="checkbox"
name="ctl00$cphGlobalContent$FormView1$Repeater1$ctl07$CategoryID"><label for="ctl00_cphGlobalContent_FormView1_Repeater1_ctl07_CategoryID">170455</label></span>
<span class="form-check-input">
<input id="ctl00_cphGlobalContent_FormView1_Repeater1_ctl08_CategoryID" type="checkbox"
name="ctl00$cphGlobalContent$FormView1$Repeater1$ctl08$CategoryID"><label for="ctl00_cphGlobalContent_FormView1_Repeater1_ctl08_CategoryID">170456</label></span>
<span class="form-check-input">
<input id="ctl00_cphGlobalContent_FormView1_Repeater1_ctl09_CategoryID" type="checkbox"
name="ctl00$cphGlobalContent$FormView1$Repeater1$ctl09$CategoryID"><label for="ctl00_cphGlobalContent_FormView1_Repeater1_ctl09_CategoryID">170457</label></span>
<span class="form-check-input">
<input id="ctl00_cphGlobalContent_FormView1_Repeater1_ctl10_CategoryID" type="checkbox"
name="ctl00$cphGlobalContent$FormView1$Repeater1$ctl10$CategoryID"><label for="ctl00_cphGlobalContent_FormView1_Repeater1_ctl10_CategoryID">170458</label></span>
<span class="form-check-input">
<input id="ctl00_cphGlobalContent_FormView1_Repeater1_ctl11_CategoryID" type="checkbox"
name="ctl00$cphGlobalContent$FormView1$Repeater1$ctl11$CategoryID"><label for="ctl00_cphGlobalContent_FormView1_Repeater1_ctl11_CategoryID">170459</label></span>
<span class="form-check-input">
<input id="ctl00_cphGlobalContent_FormView1_Repeater1_ctl12_CategoryID" type="checkbox"
name="ctl00$cphGlobalContent$FormView1$Repeater1$ctl12$CategoryID"><label for="ctl00_cphGlobalContent_FormView1_Repeater1_ctl12_CategoryID">170460</label></span>
</div>
</td>
</tr>
</tbody>
</table>
<br />
<input type="submit" name="btnAgregar" value="Agregar" id="btnAgregar" />
</div>
</form>
</body>
</html>
Demo