I have a table which populates each row with the user and a numerical stepper(@Html.EditorFor
) as well as a set of date pickers. When I try to pass the value of the numerical stepper and date fields into an array, it doesn't appear get the value like it does for the user's names which are simply text. Any recommendations?
MVC Partial View Code (Table Code):
@foreach (var x in Model.Team)
{
<tr class="">
<td>@Html.DisplayFor(modelItem => x.UserFullName)</td> @*Column 0*@
<td>@Html.EditorFor(modelItem => x.CurrentTicketLevel, "", new { htmlAttributes = new { type = "number", min = 6, max = 110, @class = "form-control", @style = "width:70px;", @id = "TicketCounts" } })</td> @*Column 1*@
<td class="StartDateField" id="StartDateField">
@*Column 3*@
<div class="input-group">
<span title="Select Start Date" class="input-group-addon" id="basic-addon1"><a class="glyphicon glyphicon-calendar"></a></span>
@Html.EditorFor(modelItem => x.StartDate, "", new { htmlAttributes = new { @class = "startdate form-control", @id = "UStartDateField", @style = "width:120px" } })
</div>
</td>
<td class="EndDateField" id="EndDateField">
<div class="input-group">
<span title="Select End Date" class="input-group-addon" id="basic-addon1"><a class="glyphicon glyphicon-calendar"></a></span>
@Html.EditorFor(modelItem => x.EndDate, "", new { htmlAttributes = new { @class = "enddate form-control", @id = "UEndDateField", @style = "width:120px" } })
</div>
</td>
</tr>
}
JQuery Code
$("#TicketCounts,#UStartDateField").on('change',function readTblValues() {
var TableData = '';
$('#tbTableValues').empty(); // clear textbox
$('#memberTable tr').each(function (row, tr) {
TableData = TableData
+ $(tr).find('td:eq(0)').text() + ' ' // Associate Name
+ $(tr).find('td:eq(1)').text() + ' '
+ '\n';
});
$("#TicketCounts,#UStartDateField").on('change',function readTblValues() {
storeTblChanges();
})
//function to save table data to array
function storeTblChanges() {
var TableData = new Array();
$('#memberTable tr').each(function (row, tr) {
TableData[row] = {
"RepID": $(tr).find('td:eq(0)').text() + ' ' //RepID
, "Tickets": $(tr).find('td:eq(1)').text() + ' ' //Ticket Count
, "StartDate": $(tr).find('td:eq(2)').text() + ' ' //StartDate
, "EndDate": $(tr).find('td:eq(3)').text() + ' ' //EndDate
} //End of TableData[row]
});//End each function
TableData.shift();
console.log(TableData)
return TableData;
}//End fn storeTblChanges()
In the first row of the console.log output
, tickets:
should have 100
and StartDate:
should have 9/20/2017