i need to subtract the amount when i click the checkbox. but my textbox amount didnot change the value inputed. when ill try to alert the total the value is show correct. how can i change the value of textbox amount when i click checkbox. thanks
- @Html.LabelFor(x => x.Amount, new { @class = "form-label" })
- @Html.TextBoxFor(x => x.Amount, new { @class = "form-control", @id = "Amount" })
- $(function () {
- $('#Payable').DataTable({
- "ajax": "@Url.Action("getpayablelist", "payment")",
- "columns": [
- {
- "render": function (data, type, full, meta) {
- return "<input type='checkbox' class='checkbox' onclick='add(" + full.Id + ", " + full.Amount + ", this.checked)'>"
- }
- },
- { "data": "Type" },
- { "data": "ReferenceNo" },
- { "data": "Amount" }
- ]
- });
- });
-
- ar ids = [];
- function add(id, amount, isChecked) {
- var total = $('#Amount').val();
- if (isChecked) {
- ids.push(id);
- total = total - amount;
- alert(total);
- }
- else {
- var i = ids.indexOf(id);
- ids.splice(i, 1);
- }
- }