I am working on a MVC app and right now I am stuck on the following problem: I have checkboxes generated from one of my models, however I don't know how to get the value(either name of id) of the selected ones in javascript. Any ideas ?
Here's the code:
@if (Model.Controls.Any())
{
for (int x = 0; x < Model.Controls.Count(); x++)
{
<div aria-autocomplete="inline">
@Html.CheckBoxFor(p => p.Controls[x].IsSelected, new { @class = "CCB" })
@Html.Label(Model.Controls[x].Name)
@Html.HiddenFor(p => p.Controls[x].ID)
</div>
}
}
Working with :
$(document).ready(function () {
$('.CCB').change(function (event) {
var matches = [];
$(".CCB:checked").each(function () {
matches.push(this.value);
});
alert(matches);
});
});