Здесь я пытаюсь добавить два десятичных значения в строке var totalSum = (grandTotal + getShippingCost).toFixed(3);
и поместить значение в var getSumTd = $("tr#sumTr").find("span#sumSpan");
.
Но проблема в том, что var totalSum = (grandTotal + getShippingCost).toFixed(3);
выдает ошибку, говорящую Uncaught TypeError: value.toFixed is not a function
.
Любая помощь с моим кодом будет отличной помощью.
Ниже мой сценарий
<script>
$('button#value-plus').on('click', function () {
debugger;
var divUpd = $(this).closest("tr").find('#qnty');
var subtotalcontainer = $(this).closest("tr").find('span#subtotal');
var mainGrandTotalcontainer = $("tr#mainGtTr").find("#mainGt");
var mainGtVal = parseFloat($("tr#mainGtTr").find('span#shippingCost').text());
var getSumTd = $("tr#sumTr").find("span#sumSpan");
var getShippingCost = parseFloat($("tr#mainGtTr").find('span#mainGt1').text());
var bklId = $(this).closest("tr").find('#pid').val();
var url = "/Product/incrementcart";
$.getJSON(url, { prdid: bklId }, function (data) {
debugger;
divUpd.val(data.qty);
var subTotal = data.qty * data.price;
subtotalcontainer.text(subTotal.toFixed(2));
var grandTotal = (mainGtVal + data.price).toFixed(3);
mainGrandTotalcontainer.text(grandTotal);
var totalSum = (grandTotal + getShippingCost).toFixed(3);
getSumTd.text(totalSum);
}).success(function () {
debugger
var url = "/Product/cartupdate";
$.get(url, function (data) {
debugger;
$(".shopping_button").html(data);
})
});
});
Ниже мой HTML
<tbody>
@foreach (var item in Model)
{
<tr>
@Html.HiddenFor(model => item.ProductId, htmlAttributes: new { @id = "pid" })
<td data-title="Product Image & name" class="t_md_align_c">
<img src="images/quick_view_img_10.jpg" alt="" class="m_md_bottom_5 d_xs_block d_xs_centered">
<a href="#" class="d_inline_b m_left_5 color_dark">@Html.DisplayFor(modelItem => item.ProductName)</a>
</td>
<td data-title="Stock">
@Html.DisplayFor(modelItem => item.Instock)
</td>
<td data-title="Price">
<p class="f_size_large color_dark">$@Html.DisplayFor(modelItem => item.ProductPrice)</p>
</td>
<td data-title="Quantity">
<div class="clearfix quantity r_corners d_inline_middle f_size_medium color_dark m_bottom_10">
<button class="bg_tr d_block f_left" data-direction="down" id="value-minus">-</button>
<input type="text" name="" id="qnty" readonly value="@item.Quantity" class="f_left">
<button class="bg_tr d_block f_left" data-direction="up" id="value-plus">+</button>
</div>
</td>
<td data-title="Subtotal">
<p class="f_size_large fw_medium scheme_color">$<span id="subtotal">@Html.DisplayFor(modelItem => item.Total)</span></p>
</td>
<td data-title="Remove">
<a href="#" class="color_dark"><i class="fa fa-times f_size_medium m_right_5"></i>Remove</a><br>
</td>
</tr>
}
<tr id="mainGtTr">
<td colspan="4" class="v_align_m d_ib_offset_large t_xs_align_l">
<div class="d_ib_offset_0 d_inline_middle half_column d_xs_block w_xs_full m_xs_bottom_5">
<button class="button_type_6 bg_scheme_color f_size_large r_corners tr_all_hover color_light m_bottom_20">Check Out </button>
</div>
<p class="fw_medium f_size_large t_align_r scheme_color p_xs_hr_0 d_inline_middle half_column d_ib_offset_normal d_xs_block w_xs_full t_xs_align_c">Grand Total:</p>
</td>
<td colspan="2" class="v_align_m">
<p class="fw_medium f_size_large scheme_color m_xs_bottom_10">$<span id="mainGt">@ViewBag.SubTotal</span></p>
<p style="font-style:oblique">Include <i class="fa fa-rupee"></i> <span id="shippingCost">@ViewBag.ShipingCost</span> shipping cost</p>
</td>
</tr>
@{
var sum = ViewBag.SubTotal + ViewBag.ShipingCost;
}
<tr id="sumTr">
<td>
<span id="sumSpan">@sum</span>
</td>
</tr>
</tbody>