I have a website about medicines and i want to calculate the total sum of checked medicines (i have price) and for that im using a JS script but when i check the checkboxes the return i get is "NaN" instead of the price. Can i get some help solving this issue?
Here is my Table:
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Quantity)
</td>
<td>
@Html.DisplayFor(modelItem => item.Price)
</td>
<td>
@if (User.IsInRole("Administrator"))
{
@Html.ActionLink("Edit", "Edit", new { id = item.Id }, new { @class = "btn btn-info" })
<button data-id="@item.Id" class="btn btn-warning js-delete">Delete</button>
}
@if (User.IsInRole("Pharmacist"))
{
@item.Id<input type="checkbox" name="selectedNames" value="@item.Id" />
}
</td>
</tr>
}
<p id="tot"></p>
and here is my JS:
$(function () {
var total;
var checked = $('input:checkbox').click(function (e) {
calculateSum();
});
function calculateSum() {
var $checked = $(':checkbox:checked');
total = 0.0;
$checked.each(function () {
total += parseFloat($(this).next().text());
});
$('#tot').text("Total Amount: " + total.toFixed(2));
}
})