So I have this concept (which I'm open to the possibility of it being a bad concept) to loop through a dynamic number of checkboxes and take the name of each checkbox that has been selected and push it to a hidden text field on my form so that the values of the names of those checkboxes that have been selected can be used elsewhere in my application. However, being somewhat new to JQuery I'm not sure if this can be done or how it can be done. This is what I've got so far with my research:
Relevant JQuery:
$('#saveButton').click(function () {
$('checkbox').each(function () {
if ($(this).is(':checked')) {
$('#hiddenDate').append($(this).text());
}
});
});
Relevant View code:
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<% using (Html.BeginForm("SaveExit", "User", new { }, FormMethod.Post, new { id = "selectExitPoints" })) { %>
<fieldset>
<div class="title center xl">Event Exit Selection </div>
<table class="data-table">
<%var odd = true; %>
<%foreach (var log in Model.Log.OrderBy(s => s.DateEntered))
{ %>
<tr class="row_<%=(odd ? "odd" : "even")%>">
<td><input class="skill-checkbox" name="<%=log.DateEntered%>" type="checkbox" /></td>
<td><span class="skill-text"><%= log.DateEntered%></span></td>
<td><span class="skill-text"><%= log.EntryAccessPoint %></span></td>
</tr>
<%odd = !odd;%>
<% } %>
</table>
<input type="hidden" id="hiddenDate" />
</fieldset>
<% } %>
Can anybody point me in the right direction?
hiddenDateis going to get really long.$('checkbox')should be$(':checkbox')or, better yet,$('[type=checkbox]')