Auto billing using javascript





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















I am try to auto bill calculation but, I didn't get how to the auto bill. when I entering cost, when show on the price input field but I didn't get how to display the total price in total filed without using button, please can any can help me .
Here my code






function calc(idx) {
var cost = 0;
var qty = 0;
var del = 0;

var price = parseFloat(document.getElementById("cost" + idx).value)
+ parseFloat(document.getElementById("del" + idx).value)
+ parseFloat(document.getElementById("qty" + idx).value);

document.getElementById("price" + idx).value = isNaN(price) ? "0.00" : price.toFixed(3);
}

function totalIt() {
var qtys = document.getElementsByName("qty");
var total = 0;
for (var i = 1; i <= qtys.length; i++) {
calc(i);
var price = parseFloat(document.getElementById("price" + i).value);
total += isNaN(price) ? 0 : price;
}

document.getElementById("total").value = isNaN(total) ? "0.00" : total.toFixed(3);
}


window.onload = function () {
document.getElementsByName("qty")[0].onkeyup = function () {
calc(1)
};
document.getElementsByName("cost")[0].onkeyup = function () {
calc(1)
};
document.getElementsByName("del")[0].onkeyup = function () {
calc(1)
};
};

var rowCount = 0;

function addRow(tableID) {
var table = document.getElementById(tableID);

var rowCount = table.rows.length;
var row = table.insertRow(rowCount);

var cell1 = row.insertCell(0);
var element1 = document.createElement("input");
element1.type = "checkbox";

element1.name = "chk";
cell1.appendChild(element1);

var cell2 = row.insertCell(1);
cell2.innerHTML = rowCount;

var cell3 = row.insertCell(2);
var element3 = document.createElement("input");
element3.type = "text";
element3.name = "item";
element3.required = "required";
cell3.appendChild(element3);

var cell4 = row.insertCell(3);
var element4 = document.createElement("input");
element4.type = "text";
element4.name = "qty";
element4.defaultValue = 0;
element4.id = "qty" + rowCount;
element4.onkeyup = function () {
calc(rowCount);
};
cell4.appendChild(element4);

var cell5 = row.insertCell(4);
var element5 = document.createElement("input");
element5.type = "text";
element5.name = "cost";
element5.value = 0;
element5.id = "cost" + rowCount;
element5.onkeyup = function () {
calc(rowCount);
};
cell5.appendChild(element5);

var cell5 = row.insertCell(4);
var element5 = document.createElement("input");
element5.type = "text";
element5.value = 0;
element5.name = "del";
element5.id = "del" + rowCount;
element5.onkeyup = function () {
calc(rowCount);
};
cell5.appendChild(element5);

var cell6 = row.insertCell(6);
var element6 = document.createElement("input");
element6.type = "text";
element6.name = "price";
element6.id = "price" + rowCount
cell6.appendChild(element6);
}

function deleteRow(tableID) {
try {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;

for (var i = 0; i < rowCount; i++) {
var row = table.rows[i];
var chkbox = row.cells[0].childNodes[0];
if (null != chkbox && true == chkbox.checked) {
table.deleteRow(i);
rowCount--;
i--;
}
}
} catch (e) {
alert(e);
}
}

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<body class="bg-info">

<section>
<div class="container">
<h3 class="text-danger">Add your Products</h3>
<input class="btn btn-success" type="button" value="Add Item " onclick="addRow('dataTable')" />

<input class="btn btn-Dark" type="button" value="Delete Item" onclick="deleteRow('dataTable')" />
<form action="" method="post" enctype="multipart/form-data">


<table id="dataTable" >
<tr>
<th style="padding-right:15px;">Select</th>
&nbsp;
<th style="padding-right:15px;">Sr. No.</th>

<th>Item Name</th>

<th>Cost</th>
<th>gst Tax</th>
<th>delivery charges</th>
<th formula="cost+qty+del"summary="sum">Price</th>

</tr>
<tr>
<td><input type="checkbox" name="chk"/></td>
<td> 1 </td>
<td> <input type="text" name="item "/> </td>
<td> <input type="text" Value =0 id="qty1" name="qty"/></td>
<td> <input type="text" Value =0 id="cost1" name="cost" /></td>
<td> <input type="text" Value =0 id="del1" name="del" /></td>
<td> <input type="text" id="price1" name="price" /> </td>
</tr>

</table>
<br/>
<div class="total" style="text-align:right;padding-right:80px;" >
Total: <input class="btn btn-Dark" type="text" readonly="readonly"name="total" onkeyup="totalIt()"id="total" /><br/><br/>
<input class="btn btn-Dark"type="button" value="Total" onkeydown="totalIt()" /> &nbsp;<input class="btn btn-success"type="submit" />

</div>

</form> </div> </section>

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
<script>
</script>












share|improve this question




















  • 1





    use onInput event handler

    – Towkir Ahmed
    Nov 16 '18 at 13:01


















1















I am try to auto bill calculation but, I didn't get how to the auto bill. when I entering cost, when show on the price input field but I didn't get how to display the total price in total filed without using button, please can any can help me .
Here my code






function calc(idx) {
var cost = 0;
var qty = 0;
var del = 0;

var price = parseFloat(document.getElementById("cost" + idx).value)
+ parseFloat(document.getElementById("del" + idx).value)
+ parseFloat(document.getElementById("qty" + idx).value);

document.getElementById("price" + idx).value = isNaN(price) ? "0.00" : price.toFixed(3);
}

function totalIt() {
var qtys = document.getElementsByName("qty");
var total = 0;
for (var i = 1; i <= qtys.length; i++) {
calc(i);
var price = parseFloat(document.getElementById("price" + i).value);
total += isNaN(price) ? 0 : price;
}

document.getElementById("total").value = isNaN(total) ? "0.00" : total.toFixed(3);
}


window.onload = function () {
document.getElementsByName("qty")[0].onkeyup = function () {
calc(1)
};
document.getElementsByName("cost")[0].onkeyup = function () {
calc(1)
};
document.getElementsByName("del")[0].onkeyup = function () {
calc(1)
};
};

var rowCount = 0;

function addRow(tableID) {
var table = document.getElementById(tableID);

var rowCount = table.rows.length;
var row = table.insertRow(rowCount);

var cell1 = row.insertCell(0);
var element1 = document.createElement("input");
element1.type = "checkbox";

element1.name = "chk";
cell1.appendChild(element1);

var cell2 = row.insertCell(1);
cell2.innerHTML = rowCount;

var cell3 = row.insertCell(2);
var element3 = document.createElement("input");
element3.type = "text";
element3.name = "item";
element3.required = "required";
cell3.appendChild(element3);

var cell4 = row.insertCell(3);
var element4 = document.createElement("input");
element4.type = "text";
element4.name = "qty";
element4.defaultValue = 0;
element4.id = "qty" + rowCount;
element4.onkeyup = function () {
calc(rowCount);
};
cell4.appendChild(element4);

var cell5 = row.insertCell(4);
var element5 = document.createElement("input");
element5.type = "text";
element5.name = "cost";
element5.value = 0;
element5.id = "cost" + rowCount;
element5.onkeyup = function () {
calc(rowCount);
};
cell5.appendChild(element5);

var cell5 = row.insertCell(4);
var element5 = document.createElement("input");
element5.type = "text";
element5.value = 0;
element5.name = "del";
element5.id = "del" + rowCount;
element5.onkeyup = function () {
calc(rowCount);
};
cell5.appendChild(element5);

var cell6 = row.insertCell(6);
var element6 = document.createElement("input");
element6.type = "text";
element6.name = "price";
element6.id = "price" + rowCount
cell6.appendChild(element6);
}

function deleteRow(tableID) {
try {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;

for (var i = 0; i < rowCount; i++) {
var row = table.rows[i];
var chkbox = row.cells[0].childNodes[0];
if (null != chkbox && true == chkbox.checked) {
table.deleteRow(i);
rowCount--;
i--;
}
}
} catch (e) {
alert(e);
}
}

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<body class="bg-info">

<section>
<div class="container">
<h3 class="text-danger">Add your Products</h3>
<input class="btn btn-success" type="button" value="Add Item " onclick="addRow('dataTable')" />

<input class="btn btn-Dark" type="button" value="Delete Item" onclick="deleteRow('dataTable')" />
<form action="" method="post" enctype="multipart/form-data">


<table id="dataTable" >
<tr>
<th style="padding-right:15px;">Select</th>
&nbsp;
<th style="padding-right:15px;">Sr. No.</th>

<th>Item Name</th>

<th>Cost</th>
<th>gst Tax</th>
<th>delivery charges</th>
<th formula="cost+qty+del"summary="sum">Price</th>

</tr>
<tr>
<td><input type="checkbox" name="chk"/></td>
<td> 1 </td>
<td> <input type="text" name="item "/> </td>
<td> <input type="text" Value =0 id="qty1" name="qty"/></td>
<td> <input type="text" Value =0 id="cost1" name="cost" /></td>
<td> <input type="text" Value =0 id="del1" name="del" /></td>
<td> <input type="text" id="price1" name="price" /> </td>
</tr>

</table>
<br/>
<div class="total" style="text-align:right;padding-right:80px;" >
Total: <input class="btn btn-Dark" type="text" readonly="readonly"name="total" onkeyup="totalIt()"id="total" /><br/><br/>
<input class="btn btn-Dark"type="button" value="Total" onkeydown="totalIt()" /> &nbsp;<input class="btn btn-success"type="submit" />

</div>

</form> </div> </section>

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
<script>
</script>












share|improve this question




















  • 1





    use onInput event handler

    – Towkir Ahmed
    Nov 16 '18 at 13:01














1












1








1








I am try to auto bill calculation but, I didn't get how to the auto bill. when I entering cost, when show on the price input field but I didn't get how to display the total price in total filed without using button, please can any can help me .
Here my code






function calc(idx) {
var cost = 0;
var qty = 0;
var del = 0;

var price = parseFloat(document.getElementById("cost" + idx).value)
+ parseFloat(document.getElementById("del" + idx).value)
+ parseFloat(document.getElementById("qty" + idx).value);

document.getElementById("price" + idx).value = isNaN(price) ? "0.00" : price.toFixed(3);
}

function totalIt() {
var qtys = document.getElementsByName("qty");
var total = 0;
for (var i = 1; i <= qtys.length; i++) {
calc(i);
var price = parseFloat(document.getElementById("price" + i).value);
total += isNaN(price) ? 0 : price;
}

document.getElementById("total").value = isNaN(total) ? "0.00" : total.toFixed(3);
}


window.onload = function () {
document.getElementsByName("qty")[0].onkeyup = function () {
calc(1)
};
document.getElementsByName("cost")[0].onkeyup = function () {
calc(1)
};
document.getElementsByName("del")[0].onkeyup = function () {
calc(1)
};
};

var rowCount = 0;

function addRow(tableID) {
var table = document.getElementById(tableID);

var rowCount = table.rows.length;
var row = table.insertRow(rowCount);

var cell1 = row.insertCell(0);
var element1 = document.createElement("input");
element1.type = "checkbox";

element1.name = "chk";
cell1.appendChild(element1);

var cell2 = row.insertCell(1);
cell2.innerHTML = rowCount;

var cell3 = row.insertCell(2);
var element3 = document.createElement("input");
element3.type = "text";
element3.name = "item";
element3.required = "required";
cell3.appendChild(element3);

var cell4 = row.insertCell(3);
var element4 = document.createElement("input");
element4.type = "text";
element4.name = "qty";
element4.defaultValue = 0;
element4.id = "qty" + rowCount;
element4.onkeyup = function () {
calc(rowCount);
};
cell4.appendChild(element4);

var cell5 = row.insertCell(4);
var element5 = document.createElement("input");
element5.type = "text";
element5.name = "cost";
element5.value = 0;
element5.id = "cost" + rowCount;
element5.onkeyup = function () {
calc(rowCount);
};
cell5.appendChild(element5);

var cell5 = row.insertCell(4);
var element5 = document.createElement("input");
element5.type = "text";
element5.value = 0;
element5.name = "del";
element5.id = "del" + rowCount;
element5.onkeyup = function () {
calc(rowCount);
};
cell5.appendChild(element5);

var cell6 = row.insertCell(6);
var element6 = document.createElement("input");
element6.type = "text";
element6.name = "price";
element6.id = "price" + rowCount
cell6.appendChild(element6);
}

function deleteRow(tableID) {
try {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;

for (var i = 0; i < rowCount; i++) {
var row = table.rows[i];
var chkbox = row.cells[0].childNodes[0];
if (null != chkbox && true == chkbox.checked) {
table.deleteRow(i);
rowCount--;
i--;
}
}
} catch (e) {
alert(e);
}
}

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<body class="bg-info">

<section>
<div class="container">
<h3 class="text-danger">Add your Products</h3>
<input class="btn btn-success" type="button" value="Add Item " onclick="addRow('dataTable')" />

<input class="btn btn-Dark" type="button" value="Delete Item" onclick="deleteRow('dataTable')" />
<form action="" method="post" enctype="multipart/form-data">


<table id="dataTable" >
<tr>
<th style="padding-right:15px;">Select</th>
&nbsp;
<th style="padding-right:15px;">Sr. No.</th>

<th>Item Name</th>

<th>Cost</th>
<th>gst Tax</th>
<th>delivery charges</th>
<th formula="cost+qty+del"summary="sum">Price</th>

</tr>
<tr>
<td><input type="checkbox" name="chk"/></td>
<td> 1 </td>
<td> <input type="text" name="item "/> </td>
<td> <input type="text" Value =0 id="qty1" name="qty"/></td>
<td> <input type="text" Value =0 id="cost1" name="cost" /></td>
<td> <input type="text" Value =0 id="del1" name="del" /></td>
<td> <input type="text" id="price1" name="price" /> </td>
</tr>

</table>
<br/>
<div class="total" style="text-align:right;padding-right:80px;" >
Total: <input class="btn btn-Dark" type="text" readonly="readonly"name="total" onkeyup="totalIt()"id="total" /><br/><br/>
<input class="btn btn-Dark"type="button" value="Total" onkeydown="totalIt()" /> &nbsp;<input class="btn btn-success"type="submit" />

</div>

</form> </div> </section>

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
<script>
</script>












share|improve this question
















I am try to auto bill calculation but, I didn't get how to the auto bill. when I entering cost, when show on the price input field but I didn't get how to display the total price in total filed without using button, please can any can help me .
Here my code






function calc(idx) {
var cost = 0;
var qty = 0;
var del = 0;

var price = parseFloat(document.getElementById("cost" + idx).value)
+ parseFloat(document.getElementById("del" + idx).value)
+ parseFloat(document.getElementById("qty" + idx).value);

document.getElementById("price" + idx).value = isNaN(price) ? "0.00" : price.toFixed(3);
}

function totalIt() {
var qtys = document.getElementsByName("qty");
var total = 0;
for (var i = 1; i <= qtys.length; i++) {
calc(i);
var price = parseFloat(document.getElementById("price" + i).value);
total += isNaN(price) ? 0 : price;
}

document.getElementById("total").value = isNaN(total) ? "0.00" : total.toFixed(3);
}


window.onload = function () {
document.getElementsByName("qty")[0].onkeyup = function () {
calc(1)
};
document.getElementsByName("cost")[0].onkeyup = function () {
calc(1)
};
document.getElementsByName("del")[0].onkeyup = function () {
calc(1)
};
};

var rowCount = 0;

function addRow(tableID) {
var table = document.getElementById(tableID);

var rowCount = table.rows.length;
var row = table.insertRow(rowCount);

var cell1 = row.insertCell(0);
var element1 = document.createElement("input");
element1.type = "checkbox";

element1.name = "chk";
cell1.appendChild(element1);

var cell2 = row.insertCell(1);
cell2.innerHTML = rowCount;

var cell3 = row.insertCell(2);
var element3 = document.createElement("input");
element3.type = "text";
element3.name = "item";
element3.required = "required";
cell3.appendChild(element3);

var cell4 = row.insertCell(3);
var element4 = document.createElement("input");
element4.type = "text";
element4.name = "qty";
element4.defaultValue = 0;
element4.id = "qty" + rowCount;
element4.onkeyup = function () {
calc(rowCount);
};
cell4.appendChild(element4);

var cell5 = row.insertCell(4);
var element5 = document.createElement("input");
element5.type = "text";
element5.name = "cost";
element5.value = 0;
element5.id = "cost" + rowCount;
element5.onkeyup = function () {
calc(rowCount);
};
cell5.appendChild(element5);

var cell5 = row.insertCell(4);
var element5 = document.createElement("input");
element5.type = "text";
element5.value = 0;
element5.name = "del";
element5.id = "del" + rowCount;
element5.onkeyup = function () {
calc(rowCount);
};
cell5.appendChild(element5);

var cell6 = row.insertCell(6);
var element6 = document.createElement("input");
element6.type = "text";
element6.name = "price";
element6.id = "price" + rowCount
cell6.appendChild(element6);
}

function deleteRow(tableID) {
try {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;

for (var i = 0; i < rowCount; i++) {
var row = table.rows[i];
var chkbox = row.cells[0].childNodes[0];
if (null != chkbox && true == chkbox.checked) {
table.deleteRow(i);
rowCount--;
i--;
}
}
} catch (e) {
alert(e);
}
}

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<body class="bg-info">

<section>
<div class="container">
<h3 class="text-danger">Add your Products</h3>
<input class="btn btn-success" type="button" value="Add Item " onclick="addRow('dataTable')" />

<input class="btn btn-Dark" type="button" value="Delete Item" onclick="deleteRow('dataTable')" />
<form action="" method="post" enctype="multipart/form-data">


<table id="dataTable" >
<tr>
<th style="padding-right:15px;">Select</th>
&nbsp;
<th style="padding-right:15px;">Sr. No.</th>

<th>Item Name</th>

<th>Cost</th>
<th>gst Tax</th>
<th>delivery charges</th>
<th formula="cost+qty+del"summary="sum">Price</th>

</tr>
<tr>
<td><input type="checkbox" name="chk"/></td>
<td> 1 </td>
<td> <input type="text" name="item "/> </td>
<td> <input type="text" Value =0 id="qty1" name="qty"/></td>
<td> <input type="text" Value =0 id="cost1" name="cost" /></td>
<td> <input type="text" Value =0 id="del1" name="del" /></td>
<td> <input type="text" id="price1" name="price" /> </td>
</tr>

</table>
<br/>
<div class="total" style="text-align:right;padding-right:80px;" >
Total: <input class="btn btn-Dark" type="text" readonly="readonly"name="total" onkeyup="totalIt()"id="total" /><br/><br/>
<input class="btn btn-Dark"type="button" value="Total" onkeydown="totalIt()" /> &nbsp;<input class="btn btn-success"type="submit" />

</div>

</form> </div> </section>

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
<script>
</script>








function calc(idx) {
var cost = 0;
var qty = 0;
var del = 0;

var price = parseFloat(document.getElementById("cost" + idx).value)
+ parseFloat(document.getElementById("del" + idx).value)
+ parseFloat(document.getElementById("qty" + idx).value);

document.getElementById("price" + idx).value = isNaN(price) ? "0.00" : price.toFixed(3);
}

function totalIt() {
var qtys = document.getElementsByName("qty");
var total = 0;
for (var i = 1; i <= qtys.length; i++) {
calc(i);
var price = parseFloat(document.getElementById("price" + i).value);
total += isNaN(price) ? 0 : price;
}

document.getElementById("total").value = isNaN(total) ? "0.00" : total.toFixed(3);
}


window.onload = function () {
document.getElementsByName("qty")[0].onkeyup = function () {
calc(1)
};
document.getElementsByName("cost")[0].onkeyup = function () {
calc(1)
};
document.getElementsByName("del")[0].onkeyup = function () {
calc(1)
};
};

var rowCount = 0;

function addRow(tableID) {
var table = document.getElementById(tableID);

var rowCount = table.rows.length;
var row = table.insertRow(rowCount);

var cell1 = row.insertCell(0);
var element1 = document.createElement("input");
element1.type = "checkbox";

element1.name = "chk";
cell1.appendChild(element1);

var cell2 = row.insertCell(1);
cell2.innerHTML = rowCount;

var cell3 = row.insertCell(2);
var element3 = document.createElement("input");
element3.type = "text";
element3.name = "item";
element3.required = "required";
cell3.appendChild(element3);

var cell4 = row.insertCell(3);
var element4 = document.createElement("input");
element4.type = "text";
element4.name = "qty";
element4.defaultValue = 0;
element4.id = "qty" + rowCount;
element4.onkeyup = function () {
calc(rowCount);
};
cell4.appendChild(element4);

var cell5 = row.insertCell(4);
var element5 = document.createElement("input");
element5.type = "text";
element5.name = "cost";
element5.value = 0;
element5.id = "cost" + rowCount;
element5.onkeyup = function () {
calc(rowCount);
};
cell5.appendChild(element5);

var cell5 = row.insertCell(4);
var element5 = document.createElement("input");
element5.type = "text";
element5.value = 0;
element5.name = "del";
element5.id = "del" + rowCount;
element5.onkeyup = function () {
calc(rowCount);
};
cell5.appendChild(element5);

var cell6 = row.insertCell(6);
var element6 = document.createElement("input");
element6.type = "text";
element6.name = "price";
element6.id = "price" + rowCount
cell6.appendChild(element6);
}

function deleteRow(tableID) {
try {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;

for (var i = 0; i < rowCount; i++) {
var row = table.rows[i];
var chkbox = row.cells[0].childNodes[0];
if (null != chkbox && true == chkbox.checked) {
table.deleteRow(i);
rowCount--;
i--;
}
}
} catch (e) {
alert(e);
}
}

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<body class="bg-info">

<section>
<div class="container">
<h3 class="text-danger">Add your Products</h3>
<input class="btn btn-success" type="button" value="Add Item " onclick="addRow('dataTable')" />

<input class="btn btn-Dark" type="button" value="Delete Item" onclick="deleteRow('dataTable')" />
<form action="" method="post" enctype="multipart/form-data">


<table id="dataTable" >
<tr>
<th style="padding-right:15px;">Select</th>
&nbsp;
<th style="padding-right:15px;">Sr. No.</th>

<th>Item Name</th>

<th>Cost</th>
<th>gst Tax</th>
<th>delivery charges</th>
<th formula="cost+qty+del"summary="sum">Price</th>

</tr>
<tr>
<td><input type="checkbox" name="chk"/></td>
<td> 1 </td>
<td> <input type="text" name="item "/> </td>
<td> <input type="text" Value =0 id="qty1" name="qty"/></td>
<td> <input type="text" Value =0 id="cost1" name="cost" /></td>
<td> <input type="text" Value =0 id="del1" name="del" /></td>
<td> <input type="text" id="price1" name="price" /> </td>
</tr>

</table>
<br/>
<div class="total" style="text-align:right;padding-right:80px;" >
Total: <input class="btn btn-Dark" type="text" readonly="readonly"name="total" onkeyup="totalIt()"id="total" /><br/><br/>
<input class="btn btn-Dark"type="button" value="Total" onkeydown="totalIt()" /> &nbsp;<input class="btn btn-success"type="submit" />

</div>

</form> </div> </section>

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
<script>
</script>





function calc(idx) {
var cost = 0;
var qty = 0;
var del = 0;

var price = parseFloat(document.getElementById("cost" + idx).value)
+ parseFloat(document.getElementById("del" + idx).value)
+ parseFloat(document.getElementById("qty" + idx).value);

document.getElementById("price" + idx).value = isNaN(price) ? "0.00" : price.toFixed(3);
}

function totalIt() {
var qtys = document.getElementsByName("qty");
var total = 0;
for (var i = 1; i <= qtys.length; i++) {
calc(i);
var price = parseFloat(document.getElementById("price" + i).value);
total += isNaN(price) ? 0 : price;
}

document.getElementById("total").value = isNaN(total) ? "0.00" : total.toFixed(3);
}


window.onload = function () {
document.getElementsByName("qty")[0].onkeyup = function () {
calc(1)
};
document.getElementsByName("cost")[0].onkeyup = function () {
calc(1)
};
document.getElementsByName("del")[0].onkeyup = function () {
calc(1)
};
};

var rowCount = 0;

function addRow(tableID) {
var table = document.getElementById(tableID);

var rowCount = table.rows.length;
var row = table.insertRow(rowCount);

var cell1 = row.insertCell(0);
var element1 = document.createElement("input");
element1.type = "checkbox";

element1.name = "chk";
cell1.appendChild(element1);

var cell2 = row.insertCell(1);
cell2.innerHTML = rowCount;

var cell3 = row.insertCell(2);
var element3 = document.createElement("input");
element3.type = "text";
element3.name = "item";
element3.required = "required";
cell3.appendChild(element3);

var cell4 = row.insertCell(3);
var element4 = document.createElement("input");
element4.type = "text";
element4.name = "qty";
element4.defaultValue = 0;
element4.id = "qty" + rowCount;
element4.onkeyup = function () {
calc(rowCount);
};
cell4.appendChild(element4);

var cell5 = row.insertCell(4);
var element5 = document.createElement("input");
element5.type = "text";
element5.name = "cost";
element5.value = 0;
element5.id = "cost" + rowCount;
element5.onkeyup = function () {
calc(rowCount);
};
cell5.appendChild(element5);

var cell5 = row.insertCell(4);
var element5 = document.createElement("input");
element5.type = "text";
element5.value = 0;
element5.name = "del";
element5.id = "del" + rowCount;
element5.onkeyup = function () {
calc(rowCount);
};
cell5.appendChild(element5);

var cell6 = row.insertCell(6);
var element6 = document.createElement("input");
element6.type = "text";
element6.name = "price";
element6.id = "price" + rowCount
cell6.appendChild(element6);
}

function deleteRow(tableID) {
try {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;

for (var i = 0; i < rowCount; i++) {
var row = table.rows[i];
var chkbox = row.cells[0].childNodes[0];
if (null != chkbox && true == chkbox.checked) {
table.deleteRow(i);
rowCount--;
i--;
}
}
} catch (e) {
alert(e);
}
}

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<body class="bg-info">

<section>
<div class="container">
<h3 class="text-danger">Add your Products</h3>
<input class="btn btn-success" type="button" value="Add Item " onclick="addRow('dataTable')" />

<input class="btn btn-Dark" type="button" value="Delete Item" onclick="deleteRow('dataTable')" />
<form action="" method="post" enctype="multipart/form-data">


<table id="dataTable" >
<tr>
<th style="padding-right:15px;">Select</th>
&nbsp;
<th style="padding-right:15px;">Sr. No.</th>

<th>Item Name</th>

<th>Cost</th>
<th>gst Tax</th>
<th>delivery charges</th>
<th formula="cost+qty+del"summary="sum">Price</th>

</tr>
<tr>
<td><input type="checkbox" name="chk"/></td>
<td> 1 </td>
<td> <input type="text" name="item "/> </td>
<td> <input type="text" Value =0 id="qty1" name="qty"/></td>
<td> <input type="text" Value =0 id="cost1" name="cost" /></td>
<td> <input type="text" Value =0 id="del1" name="del" /></td>
<td> <input type="text" id="price1" name="price" /> </td>
</tr>

</table>
<br/>
<div class="total" style="text-align:right;padding-right:80px;" >
Total: <input class="btn btn-Dark" type="text" readonly="readonly"name="total" onkeyup="totalIt()"id="total" /><br/><br/>
<input class="btn btn-Dark"type="button" value="Total" onkeydown="totalIt()" /> &nbsp;<input class="btn btn-success"type="submit" />

</div>

</form> </div> </section>

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
<script>
</script>






javascript jquery






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 '18 at 4:17







marton mar suri

















asked Nov 16 '18 at 12:58









marton mar surimarton mar suri

164




164








  • 1





    use onInput event handler

    – Towkir Ahmed
    Nov 16 '18 at 13:01














  • 1





    use onInput event handler

    – Towkir Ahmed
    Nov 16 '18 at 13:01








1




1





use onInput event handler

– Towkir Ahmed
Nov 16 '18 at 13:01





use onInput event handler

– Towkir Ahmed
Nov 16 '18 at 13:01












2 Answers
2






active

oldest

votes


















1














Update parameter in function calc(idx, iscallTotalit). Add condition in function if (!iscallTotalit). Updatecalc(i, true); in totalit() function.



Edit



document.getElementById("cost" + idx).value || 0 Added || 0 at the end so if the value is null or empty then it will replace it with 0.






function calc(idx, iscallTotalit) {
var cost = 0;
var qty = 0;
var del = 0;

var price = parseFloat(document.getElementById("cost" + idx).value || 0)
+ parseFloat(document.getElementById("del" + idx).value || 0)
+ parseFloat(document.getElementById("qty" + idx).value || 0);

document.getElementById("price" + idx).value = isNaN(price) ? "0.00" : price.toFixed(3);

if (!iscallTotalit)
totalIt();
}

function totalIt() {
var qtys = document.getElementsByName("qty");
var total = 0;
for (var i = 1; i <= qtys.length; i++) {
calc(i, true);
var price = parseFloat(document.getElementById("price" + i).value || 0);
total += isNaN(price) ? 0 : price;
}

document.getElementById("total").value = isNaN(total) ? "0.00" : total.toFixed(3);
}


window.onload = function () {
document.getElementsByName("qty")[0].onkeyup = function () {
calc(1)
};
document.getElementsByName("cost")[0].onkeyup = function () {
calc(1)
};
document.getElementsByName("del")[0].onkeyup = function () {
calc(1)
};
};

var rowCount = 0;

function addRow(tableID) {
var table = document.getElementById(tableID);

var rowCount = table.rows.length;
var row = table.insertRow(rowCount);

var cell1 = row.insertCell(0);
var element1 = document.createElement("input");
element1.type = "checkbox";

element1.name = "chk";
cell1.appendChild(element1);

var cell2 = row.insertCell(1);
cell2.innerHTML = rowCount;

var cell3 = row.insertCell(2);
var element3 = document.createElement("input");
element3.type = "text";
element3.name = "item";
element3.required = "required";
cell3.appendChild(element3);

var cell4 = row.insertCell(3);
var element4 = document.createElement("input");
element4.type = "text";
element4.name = "qty";
element4.defaultValue = 0;
element4.id = "qty" + rowCount;
element4.onkeyup = function () {
calc(rowCount);
};
cell4.appendChild(element4);

var cell5 = row.insertCell(4);
var element5 = document.createElement("input");
element5.type = "text";
element5.name = "cost";
element5.value = 0;
element5.id = "cost" + rowCount;
element5.onkeyup = function () {
calc(rowCount);
};
cell5.appendChild(element5);

var cell5 = row.insertCell(4);
var element5 = document.createElement("input");
element5.type = "text";
element5.value = 0;
element5.name = "del";
element5.id = "del" + rowCount;
element5.onkeyup = function () {
calc(rowCount);
};
cell5.appendChild(element5);

var cell6 = row.insertCell(6);
var element6 = document.createElement("input");
element6.type = "text";
element6.name = "price";
element6.id = "price" + rowCount
cell6.appendChild(element6);
}

function deleteRow(tableID) {
try {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;

for (var i = 0; i < rowCount; i++) {
var row = table.rows[i];
var chkbox = row.cells[0].childNodes[0];
if (null != chkbox && true == chkbox.checked) {
table.deleteRow(i);
rowCount--;
i--;
}
}
} catch (e) {
alert(e);
}
}

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<body class="bg-info">

<section>
<div class="container">
<h3 class="text-danger">Add your Products</h3>
<input class="btn btn-success" type="button" value="Add Item " onclick="addRow('dataTable')" />

<input class="btn btn-Dark" type="button" value="Delete Item" onclick="deleteRow('dataTable')" />
<form action="" method="post" enctype="multipart/form-data">


<table id="dataTable" >
<tr>
<th style="padding-right:15px;">Select</th>
&nbsp;
<th style="padding-right:15px;">Sr. No.</th>

<th>Item Name</th>

<th>Cost</th>
<th>gst Tax</th>
<th>delivery charges</th>
<th formula="cost+qty+del"summary="sum">Price</th>

</tr>
<tr>
<td><input type="checkbox" name="chk"/></td>
<td> 1 </td>
<td> <input type="text" name="item "/> </td>
<td> <input type="text" Value =0 id="qty1" name="qty"/></td>
<td> <input type="text" Value =0 id="cost1" name="cost" /></td>
<td> <input type="text" Value =0 id="del1" name="del" /></td>
<td> <input type="text" id="price1" name="price" /> </td>
</tr>

</table>
<br/>
<div class="total" style="text-align:right;padding-right:80px;" >
Total: <input class="btn btn-Dark" type="text" readonly="readonly"name="total" onkeyup="totalIt()"id="total" /><br/><br/>
<input class="btn btn-Dark"type="button" value="Total" onkeydown="totalIt()" /> &nbsp;<input class="btn btn-success"type="submit" />

</div>

</form> </div> </section>

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
<script>
</script>








share|improve this answer


























  • thank you Bhargava for code, when I am deleting one column values its 0 but i want to add two columns values please help me how to do

    – marton mar suri
    Nov 20 '18 at 6:39











  • Updated my Ans Please check @martonmarsuri

    – Bhargav Aboti
    Nov 20 '18 at 8:20











  • Thank you very much Bhargav Aboti

    – marton mar suri
    Nov 20 '18 at 9:46













  • You can accept the answer....

    – Bhargav Aboti
    Nov 20 '18 at 11:09



















0














Here is a simple example on how to handle the input directly:






const $source = document.querySelector('#source');
const $result = document.querySelector('#result');

const typeHandler = function(e) {
$result.innerHTML = e.target.value; //Here you can handle the event, make your calculation and display the calculated data
}

$source.addEventListener('input', typeHandler) // register for oninput
$source.addEventListener('propertychange', typeHandler) // for IE8

<input id="source" />
<div id="result"></div>








share|improve this answer
























  • hi Olli it is did not working properly.can show to its work please.

    – marton mar suri
    Nov 20 '18 at 4:53












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53338406%2fauto-billing-using-javascript%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














Update parameter in function calc(idx, iscallTotalit). Add condition in function if (!iscallTotalit). Updatecalc(i, true); in totalit() function.



Edit



document.getElementById("cost" + idx).value || 0 Added || 0 at the end so if the value is null or empty then it will replace it with 0.






function calc(idx, iscallTotalit) {
var cost = 0;
var qty = 0;
var del = 0;

var price = parseFloat(document.getElementById("cost" + idx).value || 0)
+ parseFloat(document.getElementById("del" + idx).value || 0)
+ parseFloat(document.getElementById("qty" + idx).value || 0);

document.getElementById("price" + idx).value = isNaN(price) ? "0.00" : price.toFixed(3);

if (!iscallTotalit)
totalIt();
}

function totalIt() {
var qtys = document.getElementsByName("qty");
var total = 0;
for (var i = 1; i <= qtys.length; i++) {
calc(i, true);
var price = parseFloat(document.getElementById("price" + i).value || 0);
total += isNaN(price) ? 0 : price;
}

document.getElementById("total").value = isNaN(total) ? "0.00" : total.toFixed(3);
}


window.onload = function () {
document.getElementsByName("qty")[0].onkeyup = function () {
calc(1)
};
document.getElementsByName("cost")[0].onkeyup = function () {
calc(1)
};
document.getElementsByName("del")[0].onkeyup = function () {
calc(1)
};
};

var rowCount = 0;

function addRow(tableID) {
var table = document.getElementById(tableID);

var rowCount = table.rows.length;
var row = table.insertRow(rowCount);

var cell1 = row.insertCell(0);
var element1 = document.createElement("input");
element1.type = "checkbox";

element1.name = "chk";
cell1.appendChild(element1);

var cell2 = row.insertCell(1);
cell2.innerHTML = rowCount;

var cell3 = row.insertCell(2);
var element3 = document.createElement("input");
element3.type = "text";
element3.name = "item";
element3.required = "required";
cell3.appendChild(element3);

var cell4 = row.insertCell(3);
var element4 = document.createElement("input");
element4.type = "text";
element4.name = "qty";
element4.defaultValue = 0;
element4.id = "qty" + rowCount;
element4.onkeyup = function () {
calc(rowCount);
};
cell4.appendChild(element4);

var cell5 = row.insertCell(4);
var element5 = document.createElement("input");
element5.type = "text";
element5.name = "cost";
element5.value = 0;
element5.id = "cost" + rowCount;
element5.onkeyup = function () {
calc(rowCount);
};
cell5.appendChild(element5);

var cell5 = row.insertCell(4);
var element5 = document.createElement("input");
element5.type = "text";
element5.value = 0;
element5.name = "del";
element5.id = "del" + rowCount;
element5.onkeyup = function () {
calc(rowCount);
};
cell5.appendChild(element5);

var cell6 = row.insertCell(6);
var element6 = document.createElement("input");
element6.type = "text";
element6.name = "price";
element6.id = "price" + rowCount
cell6.appendChild(element6);
}

function deleteRow(tableID) {
try {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;

for (var i = 0; i < rowCount; i++) {
var row = table.rows[i];
var chkbox = row.cells[0].childNodes[0];
if (null != chkbox && true == chkbox.checked) {
table.deleteRow(i);
rowCount--;
i--;
}
}
} catch (e) {
alert(e);
}
}

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<body class="bg-info">

<section>
<div class="container">
<h3 class="text-danger">Add your Products</h3>
<input class="btn btn-success" type="button" value="Add Item " onclick="addRow('dataTable')" />

<input class="btn btn-Dark" type="button" value="Delete Item" onclick="deleteRow('dataTable')" />
<form action="" method="post" enctype="multipart/form-data">


<table id="dataTable" >
<tr>
<th style="padding-right:15px;">Select</th>
&nbsp;
<th style="padding-right:15px;">Sr. No.</th>

<th>Item Name</th>

<th>Cost</th>
<th>gst Tax</th>
<th>delivery charges</th>
<th formula="cost+qty+del"summary="sum">Price</th>

</tr>
<tr>
<td><input type="checkbox" name="chk"/></td>
<td> 1 </td>
<td> <input type="text" name="item "/> </td>
<td> <input type="text" Value =0 id="qty1" name="qty"/></td>
<td> <input type="text" Value =0 id="cost1" name="cost" /></td>
<td> <input type="text" Value =0 id="del1" name="del" /></td>
<td> <input type="text" id="price1" name="price" /> </td>
</tr>

</table>
<br/>
<div class="total" style="text-align:right;padding-right:80px;" >
Total: <input class="btn btn-Dark" type="text" readonly="readonly"name="total" onkeyup="totalIt()"id="total" /><br/><br/>
<input class="btn btn-Dark"type="button" value="Total" onkeydown="totalIt()" /> &nbsp;<input class="btn btn-success"type="submit" />

</div>

</form> </div> </section>

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
<script>
</script>








share|improve this answer


























  • thank you Bhargava for code, when I am deleting one column values its 0 but i want to add two columns values please help me how to do

    – marton mar suri
    Nov 20 '18 at 6:39











  • Updated my Ans Please check @martonmarsuri

    – Bhargav Aboti
    Nov 20 '18 at 8:20











  • Thank you very much Bhargav Aboti

    – marton mar suri
    Nov 20 '18 at 9:46













  • You can accept the answer....

    – Bhargav Aboti
    Nov 20 '18 at 11:09
















1














Update parameter in function calc(idx, iscallTotalit). Add condition in function if (!iscallTotalit). Updatecalc(i, true); in totalit() function.



Edit



document.getElementById("cost" + idx).value || 0 Added || 0 at the end so if the value is null or empty then it will replace it with 0.






function calc(idx, iscallTotalit) {
var cost = 0;
var qty = 0;
var del = 0;

var price = parseFloat(document.getElementById("cost" + idx).value || 0)
+ parseFloat(document.getElementById("del" + idx).value || 0)
+ parseFloat(document.getElementById("qty" + idx).value || 0);

document.getElementById("price" + idx).value = isNaN(price) ? "0.00" : price.toFixed(3);

if (!iscallTotalit)
totalIt();
}

function totalIt() {
var qtys = document.getElementsByName("qty");
var total = 0;
for (var i = 1; i <= qtys.length; i++) {
calc(i, true);
var price = parseFloat(document.getElementById("price" + i).value || 0);
total += isNaN(price) ? 0 : price;
}

document.getElementById("total").value = isNaN(total) ? "0.00" : total.toFixed(3);
}


window.onload = function () {
document.getElementsByName("qty")[0].onkeyup = function () {
calc(1)
};
document.getElementsByName("cost")[0].onkeyup = function () {
calc(1)
};
document.getElementsByName("del")[0].onkeyup = function () {
calc(1)
};
};

var rowCount = 0;

function addRow(tableID) {
var table = document.getElementById(tableID);

var rowCount = table.rows.length;
var row = table.insertRow(rowCount);

var cell1 = row.insertCell(0);
var element1 = document.createElement("input");
element1.type = "checkbox";

element1.name = "chk";
cell1.appendChild(element1);

var cell2 = row.insertCell(1);
cell2.innerHTML = rowCount;

var cell3 = row.insertCell(2);
var element3 = document.createElement("input");
element3.type = "text";
element3.name = "item";
element3.required = "required";
cell3.appendChild(element3);

var cell4 = row.insertCell(3);
var element4 = document.createElement("input");
element4.type = "text";
element4.name = "qty";
element4.defaultValue = 0;
element4.id = "qty" + rowCount;
element4.onkeyup = function () {
calc(rowCount);
};
cell4.appendChild(element4);

var cell5 = row.insertCell(4);
var element5 = document.createElement("input");
element5.type = "text";
element5.name = "cost";
element5.value = 0;
element5.id = "cost" + rowCount;
element5.onkeyup = function () {
calc(rowCount);
};
cell5.appendChild(element5);

var cell5 = row.insertCell(4);
var element5 = document.createElement("input");
element5.type = "text";
element5.value = 0;
element5.name = "del";
element5.id = "del" + rowCount;
element5.onkeyup = function () {
calc(rowCount);
};
cell5.appendChild(element5);

var cell6 = row.insertCell(6);
var element6 = document.createElement("input");
element6.type = "text";
element6.name = "price";
element6.id = "price" + rowCount
cell6.appendChild(element6);
}

function deleteRow(tableID) {
try {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;

for (var i = 0; i < rowCount; i++) {
var row = table.rows[i];
var chkbox = row.cells[0].childNodes[0];
if (null != chkbox && true == chkbox.checked) {
table.deleteRow(i);
rowCount--;
i--;
}
}
} catch (e) {
alert(e);
}
}

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<body class="bg-info">

<section>
<div class="container">
<h3 class="text-danger">Add your Products</h3>
<input class="btn btn-success" type="button" value="Add Item " onclick="addRow('dataTable')" />

<input class="btn btn-Dark" type="button" value="Delete Item" onclick="deleteRow('dataTable')" />
<form action="" method="post" enctype="multipart/form-data">


<table id="dataTable" >
<tr>
<th style="padding-right:15px;">Select</th>
&nbsp;
<th style="padding-right:15px;">Sr. No.</th>

<th>Item Name</th>

<th>Cost</th>
<th>gst Tax</th>
<th>delivery charges</th>
<th formula="cost+qty+del"summary="sum">Price</th>

</tr>
<tr>
<td><input type="checkbox" name="chk"/></td>
<td> 1 </td>
<td> <input type="text" name="item "/> </td>
<td> <input type="text" Value =0 id="qty1" name="qty"/></td>
<td> <input type="text" Value =0 id="cost1" name="cost" /></td>
<td> <input type="text" Value =0 id="del1" name="del" /></td>
<td> <input type="text" id="price1" name="price" /> </td>
</tr>

</table>
<br/>
<div class="total" style="text-align:right;padding-right:80px;" >
Total: <input class="btn btn-Dark" type="text" readonly="readonly"name="total" onkeyup="totalIt()"id="total" /><br/><br/>
<input class="btn btn-Dark"type="button" value="Total" onkeydown="totalIt()" /> &nbsp;<input class="btn btn-success"type="submit" />

</div>

</form> </div> </section>

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
<script>
</script>








share|improve this answer


























  • thank you Bhargava for code, when I am deleting one column values its 0 but i want to add two columns values please help me how to do

    – marton mar suri
    Nov 20 '18 at 6:39











  • Updated my Ans Please check @martonmarsuri

    – Bhargav Aboti
    Nov 20 '18 at 8:20











  • Thank you very much Bhargav Aboti

    – marton mar suri
    Nov 20 '18 at 9:46













  • You can accept the answer....

    – Bhargav Aboti
    Nov 20 '18 at 11:09














1












1








1







Update parameter in function calc(idx, iscallTotalit). Add condition in function if (!iscallTotalit). Updatecalc(i, true); in totalit() function.



Edit



document.getElementById("cost" + idx).value || 0 Added || 0 at the end so if the value is null or empty then it will replace it with 0.






function calc(idx, iscallTotalit) {
var cost = 0;
var qty = 0;
var del = 0;

var price = parseFloat(document.getElementById("cost" + idx).value || 0)
+ parseFloat(document.getElementById("del" + idx).value || 0)
+ parseFloat(document.getElementById("qty" + idx).value || 0);

document.getElementById("price" + idx).value = isNaN(price) ? "0.00" : price.toFixed(3);

if (!iscallTotalit)
totalIt();
}

function totalIt() {
var qtys = document.getElementsByName("qty");
var total = 0;
for (var i = 1; i <= qtys.length; i++) {
calc(i, true);
var price = parseFloat(document.getElementById("price" + i).value || 0);
total += isNaN(price) ? 0 : price;
}

document.getElementById("total").value = isNaN(total) ? "0.00" : total.toFixed(3);
}


window.onload = function () {
document.getElementsByName("qty")[0].onkeyup = function () {
calc(1)
};
document.getElementsByName("cost")[0].onkeyup = function () {
calc(1)
};
document.getElementsByName("del")[0].onkeyup = function () {
calc(1)
};
};

var rowCount = 0;

function addRow(tableID) {
var table = document.getElementById(tableID);

var rowCount = table.rows.length;
var row = table.insertRow(rowCount);

var cell1 = row.insertCell(0);
var element1 = document.createElement("input");
element1.type = "checkbox";

element1.name = "chk";
cell1.appendChild(element1);

var cell2 = row.insertCell(1);
cell2.innerHTML = rowCount;

var cell3 = row.insertCell(2);
var element3 = document.createElement("input");
element3.type = "text";
element3.name = "item";
element3.required = "required";
cell3.appendChild(element3);

var cell4 = row.insertCell(3);
var element4 = document.createElement("input");
element4.type = "text";
element4.name = "qty";
element4.defaultValue = 0;
element4.id = "qty" + rowCount;
element4.onkeyup = function () {
calc(rowCount);
};
cell4.appendChild(element4);

var cell5 = row.insertCell(4);
var element5 = document.createElement("input");
element5.type = "text";
element5.name = "cost";
element5.value = 0;
element5.id = "cost" + rowCount;
element5.onkeyup = function () {
calc(rowCount);
};
cell5.appendChild(element5);

var cell5 = row.insertCell(4);
var element5 = document.createElement("input");
element5.type = "text";
element5.value = 0;
element5.name = "del";
element5.id = "del" + rowCount;
element5.onkeyup = function () {
calc(rowCount);
};
cell5.appendChild(element5);

var cell6 = row.insertCell(6);
var element6 = document.createElement("input");
element6.type = "text";
element6.name = "price";
element6.id = "price" + rowCount
cell6.appendChild(element6);
}

function deleteRow(tableID) {
try {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;

for (var i = 0; i < rowCount; i++) {
var row = table.rows[i];
var chkbox = row.cells[0].childNodes[0];
if (null != chkbox && true == chkbox.checked) {
table.deleteRow(i);
rowCount--;
i--;
}
}
} catch (e) {
alert(e);
}
}

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<body class="bg-info">

<section>
<div class="container">
<h3 class="text-danger">Add your Products</h3>
<input class="btn btn-success" type="button" value="Add Item " onclick="addRow('dataTable')" />

<input class="btn btn-Dark" type="button" value="Delete Item" onclick="deleteRow('dataTable')" />
<form action="" method="post" enctype="multipart/form-data">


<table id="dataTable" >
<tr>
<th style="padding-right:15px;">Select</th>
&nbsp;
<th style="padding-right:15px;">Sr. No.</th>

<th>Item Name</th>

<th>Cost</th>
<th>gst Tax</th>
<th>delivery charges</th>
<th formula="cost+qty+del"summary="sum">Price</th>

</tr>
<tr>
<td><input type="checkbox" name="chk"/></td>
<td> 1 </td>
<td> <input type="text" name="item "/> </td>
<td> <input type="text" Value =0 id="qty1" name="qty"/></td>
<td> <input type="text" Value =0 id="cost1" name="cost" /></td>
<td> <input type="text" Value =0 id="del1" name="del" /></td>
<td> <input type="text" id="price1" name="price" /> </td>
</tr>

</table>
<br/>
<div class="total" style="text-align:right;padding-right:80px;" >
Total: <input class="btn btn-Dark" type="text" readonly="readonly"name="total" onkeyup="totalIt()"id="total" /><br/><br/>
<input class="btn btn-Dark"type="button" value="Total" onkeydown="totalIt()" /> &nbsp;<input class="btn btn-success"type="submit" />

</div>

</form> </div> </section>

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
<script>
</script>








share|improve this answer















Update parameter in function calc(idx, iscallTotalit). Add condition in function if (!iscallTotalit). Updatecalc(i, true); in totalit() function.



Edit



document.getElementById("cost" + idx).value || 0 Added || 0 at the end so if the value is null or empty then it will replace it with 0.






function calc(idx, iscallTotalit) {
var cost = 0;
var qty = 0;
var del = 0;

var price = parseFloat(document.getElementById("cost" + idx).value || 0)
+ parseFloat(document.getElementById("del" + idx).value || 0)
+ parseFloat(document.getElementById("qty" + idx).value || 0);

document.getElementById("price" + idx).value = isNaN(price) ? "0.00" : price.toFixed(3);

if (!iscallTotalit)
totalIt();
}

function totalIt() {
var qtys = document.getElementsByName("qty");
var total = 0;
for (var i = 1; i <= qtys.length; i++) {
calc(i, true);
var price = parseFloat(document.getElementById("price" + i).value || 0);
total += isNaN(price) ? 0 : price;
}

document.getElementById("total").value = isNaN(total) ? "0.00" : total.toFixed(3);
}


window.onload = function () {
document.getElementsByName("qty")[0].onkeyup = function () {
calc(1)
};
document.getElementsByName("cost")[0].onkeyup = function () {
calc(1)
};
document.getElementsByName("del")[0].onkeyup = function () {
calc(1)
};
};

var rowCount = 0;

function addRow(tableID) {
var table = document.getElementById(tableID);

var rowCount = table.rows.length;
var row = table.insertRow(rowCount);

var cell1 = row.insertCell(0);
var element1 = document.createElement("input");
element1.type = "checkbox";

element1.name = "chk";
cell1.appendChild(element1);

var cell2 = row.insertCell(1);
cell2.innerHTML = rowCount;

var cell3 = row.insertCell(2);
var element3 = document.createElement("input");
element3.type = "text";
element3.name = "item";
element3.required = "required";
cell3.appendChild(element3);

var cell4 = row.insertCell(3);
var element4 = document.createElement("input");
element4.type = "text";
element4.name = "qty";
element4.defaultValue = 0;
element4.id = "qty" + rowCount;
element4.onkeyup = function () {
calc(rowCount);
};
cell4.appendChild(element4);

var cell5 = row.insertCell(4);
var element5 = document.createElement("input");
element5.type = "text";
element5.name = "cost";
element5.value = 0;
element5.id = "cost" + rowCount;
element5.onkeyup = function () {
calc(rowCount);
};
cell5.appendChild(element5);

var cell5 = row.insertCell(4);
var element5 = document.createElement("input");
element5.type = "text";
element5.value = 0;
element5.name = "del";
element5.id = "del" + rowCount;
element5.onkeyup = function () {
calc(rowCount);
};
cell5.appendChild(element5);

var cell6 = row.insertCell(6);
var element6 = document.createElement("input");
element6.type = "text";
element6.name = "price";
element6.id = "price" + rowCount
cell6.appendChild(element6);
}

function deleteRow(tableID) {
try {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;

for (var i = 0; i < rowCount; i++) {
var row = table.rows[i];
var chkbox = row.cells[0].childNodes[0];
if (null != chkbox && true == chkbox.checked) {
table.deleteRow(i);
rowCount--;
i--;
}
}
} catch (e) {
alert(e);
}
}

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<body class="bg-info">

<section>
<div class="container">
<h3 class="text-danger">Add your Products</h3>
<input class="btn btn-success" type="button" value="Add Item " onclick="addRow('dataTable')" />

<input class="btn btn-Dark" type="button" value="Delete Item" onclick="deleteRow('dataTable')" />
<form action="" method="post" enctype="multipart/form-data">


<table id="dataTable" >
<tr>
<th style="padding-right:15px;">Select</th>
&nbsp;
<th style="padding-right:15px;">Sr. No.</th>

<th>Item Name</th>

<th>Cost</th>
<th>gst Tax</th>
<th>delivery charges</th>
<th formula="cost+qty+del"summary="sum">Price</th>

</tr>
<tr>
<td><input type="checkbox" name="chk"/></td>
<td> 1 </td>
<td> <input type="text" name="item "/> </td>
<td> <input type="text" Value =0 id="qty1" name="qty"/></td>
<td> <input type="text" Value =0 id="cost1" name="cost" /></td>
<td> <input type="text" Value =0 id="del1" name="del" /></td>
<td> <input type="text" id="price1" name="price" /> </td>
</tr>

</table>
<br/>
<div class="total" style="text-align:right;padding-right:80px;" >
Total: <input class="btn btn-Dark" type="text" readonly="readonly"name="total" onkeyup="totalIt()"id="total" /><br/><br/>
<input class="btn btn-Dark"type="button" value="Total" onkeydown="totalIt()" /> &nbsp;<input class="btn btn-success"type="submit" />

</div>

</form> </div> </section>

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
<script>
</script>








function calc(idx, iscallTotalit) {
var cost = 0;
var qty = 0;
var del = 0;

var price = parseFloat(document.getElementById("cost" + idx).value || 0)
+ parseFloat(document.getElementById("del" + idx).value || 0)
+ parseFloat(document.getElementById("qty" + idx).value || 0);

document.getElementById("price" + idx).value = isNaN(price) ? "0.00" : price.toFixed(3);

if (!iscallTotalit)
totalIt();
}

function totalIt() {
var qtys = document.getElementsByName("qty");
var total = 0;
for (var i = 1; i <= qtys.length; i++) {
calc(i, true);
var price = parseFloat(document.getElementById("price" + i).value || 0);
total += isNaN(price) ? 0 : price;
}

document.getElementById("total").value = isNaN(total) ? "0.00" : total.toFixed(3);
}


window.onload = function () {
document.getElementsByName("qty")[0].onkeyup = function () {
calc(1)
};
document.getElementsByName("cost")[0].onkeyup = function () {
calc(1)
};
document.getElementsByName("del")[0].onkeyup = function () {
calc(1)
};
};

var rowCount = 0;

function addRow(tableID) {
var table = document.getElementById(tableID);

var rowCount = table.rows.length;
var row = table.insertRow(rowCount);

var cell1 = row.insertCell(0);
var element1 = document.createElement("input");
element1.type = "checkbox";

element1.name = "chk";
cell1.appendChild(element1);

var cell2 = row.insertCell(1);
cell2.innerHTML = rowCount;

var cell3 = row.insertCell(2);
var element3 = document.createElement("input");
element3.type = "text";
element3.name = "item";
element3.required = "required";
cell3.appendChild(element3);

var cell4 = row.insertCell(3);
var element4 = document.createElement("input");
element4.type = "text";
element4.name = "qty";
element4.defaultValue = 0;
element4.id = "qty" + rowCount;
element4.onkeyup = function () {
calc(rowCount);
};
cell4.appendChild(element4);

var cell5 = row.insertCell(4);
var element5 = document.createElement("input");
element5.type = "text";
element5.name = "cost";
element5.value = 0;
element5.id = "cost" + rowCount;
element5.onkeyup = function () {
calc(rowCount);
};
cell5.appendChild(element5);

var cell5 = row.insertCell(4);
var element5 = document.createElement("input");
element5.type = "text";
element5.value = 0;
element5.name = "del";
element5.id = "del" + rowCount;
element5.onkeyup = function () {
calc(rowCount);
};
cell5.appendChild(element5);

var cell6 = row.insertCell(6);
var element6 = document.createElement("input");
element6.type = "text";
element6.name = "price";
element6.id = "price" + rowCount
cell6.appendChild(element6);
}

function deleteRow(tableID) {
try {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;

for (var i = 0; i < rowCount; i++) {
var row = table.rows[i];
var chkbox = row.cells[0].childNodes[0];
if (null != chkbox && true == chkbox.checked) {
table.deleteRow(i);
rowCount--;
i--;
}
}
} catch (e) {
alert(e);
}
}

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<body class="bg-info">

<section>
<div class="container">
<h3 class="text-danger">Add your Products</h3>
<input class="btn btn-success" type="button" value="Add Item " onclick="addRow('dataTable')" />

<input class="btn btn-Dark" type="button" value="Delete Item" onclick="deleteRow('dataTable')" />
<form action="" method="post" enctype="multipart/form-data">


<table id="dataTable" >
<tr>
<th style="padding-right:15px;">Select</th>
&nbsp;
<th style="padding-right:15px;">Sr. No.</th>

<th>Item Name</th>

<th>Cost</th>
<th>gst Tax</th>
<th>delivery charges</th>
<th formula="cost+qty+del"summary="sum">Price</th>

</tr>
<tr>
<td><input type="checkbox" name="chk"/></td>
<td> 1 </td>
<td> <input type="text" name="item "/> </td>
<td> <input type="text" Value =0 id="qty1" name="qty"/></td>
<td> <input type="text" Value =0 id="cost1" name="cost" /></td>
<td> <input type="text" Value =0 id="del1" name="del" /></td>
<td> <input type="text" id="price1" name="price" /> </td>
</tr>

</table>
<br/>
<div class="total" style="text-align:right;padding-right:80px;" >
Total: <input class="btn btn-Dark" type="text" readonly="readonly"name="total" onkeyup="totalIt()"id="total" /><br/><br/>
<input class="btn btn-Dark"type="button" value="Total" onkeydown="totalIt()" /> &nbsp;<input class="btn btn-success"type="submit" />

</div>

</form> </div> </section>

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
<script>
</script>





function calc(idx, iscallTotalit) {
var cost = 0;
var qty = 0;
var del = 0;

var price = parseFloat(document.getElementById("cost" + idx).value || 0)
+ parseFloat(document.getElementById("del" + idx).value || 0)
+ parseFloat(document.getElementById("qty" + idx).value || 0);

document.getElementById("price" + idx).value = isNaN(price) ? "0.00" : price.toFixed(3);

if (!iscallTotalit)
totalIt();
}

function totalIt() {
var qtys = document.getElementsByName("qty");
var total = 0;
for (var i = 1; i <= qtys.length; i++) {
calc(i, true);
var price = parseFloat(document.getElementById("price" + i).value || 0);
total += isNaN(price) ? 0 : price;
}

document.getElementById("total").value = isNaN(total) ? "0.00" : total.toFixed(3);
}


window.onload = function () {
document.getElementsByName("qty")[0].onkeyup = function () {
calc(1)
};
document.getElementsByName("cost")[0].onkeyup = function () {
calc(1)
};
document.getElementsByName("del")[0].onkeyup = function () {
calc(1)
};
};

var rowCount = 0;

function addRow(tableID) {
var table = document.getElementById(tableID);

var rowCount = table.rows.length;
var row = table.insertRow(rowCount);

var cell1 = row.insertCell(0);
var element1 = document.createElement("input");
element1.type = "checkbox";

element1.name = "chk";
cell1.appendChild(element1);

var cell2 = row.insertCell(1);
cell2.innerHTML = rowCount;

var cell3 = row.insertCell(2);
var element3 = document.createElement("input");
element3.type = "text";
element3.name = "item";
element3.required = "required";
cell3.appendChild(element3);

var cell4 = row.insertCell(3);
var element4 = document.createElement("input");
element4.type = "text";
element4.name = "qty";
element4.defaultValue = 0;
element4.id = "qty" + rowCount;
element4.onkeyup = function () {
calc(rowCount);
};
cell4.appendChild(element4);

var cell5 = row.insertCell(4);
var element5 = document.createElement("input");
element5.type = "text";
element5.name = "cost";
element5.value = 0;
element5.id = "cost" + rowCount;
element5.onkeyup = function () {
calc(rowCount);
};
cell5.appendChild(element5);

var cell5 = row.insertCell(4);
var element5 = document.createElement("input");
element5.type = "text";
element5.value = 0;
element5.name = "del";
element5.id = "del" + rowCount;
element5.onkeyup = function () {
calc(rowCount);
};
cell5.appendChild(element5);

var cell6 = row.insertCell(6);
var element6 = document.createElement("input");
element6.type = "text";
element6.name = "price";
element6.id = "price" + rowCount
cell6.appendChild(element6);
}

function deleteRow(tableID) {
try {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;

for (var i = 0; i < rowCount; i++) {
var row = table.rows[i];
var chkbox = row.cells[0].childNodes[0];
if (null != chkbox && true == chkbox.checked) {
table.deleteRow(i);
rowCount--;
i--;
}
}
} catch (e) {
alert(e);
}
}

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<body class="bg-info">

<section>
<div class="container">
<h3 class="text-danger">Add your Products</h3>
<input class="btn btn-success" type="button" value="Add Item " onclick="addRow('dataTable')" />

<input class="btn btn-Dark" type="button" value="Delete Item" onclick="deleteRow('dataTable')" />
<form action="" method="post" enctype="multipart/form-data">


<table id="dataTable" >
<tr>
<th style="padding-right:15px;">Select</th>
&nbsp;
<th style="padding-right:15px;">Sr. No.</th>

<th>Item Name</th>

<th>Cost</th>
<th>gst Tax</th>
<th>delivery charges</th>
<th formula="cost+qty+del"summary="sum">Price</th>

</tr>
<tr>
<td><input type="checkbox" name="chk"/></td>
<td> 1 </td>
<td> <input type="text" name="item "/> </td>
<td> <input type="text" Value =0 id="qty1" name="qty"/></td>
<td> <input type="text" Value =0 id="cost1" name="cost" /></td>
<td> <input type="text" Value =0 id="del1" name="del" /></td>
<td> <input type="text" id="price1" name="price" /> </td>
</tr>

</table>
<br/>
<div class="total" style="text-align:right;padding-right:80px;" >
Total: <input class="btn btn-Dark" type="text" readonly="readonly"name="total" onkeyup="totalIt()"id="total" /><br/><br/>
<input class="btn btn-Dark"type="button" value="Total" onkeydown="totalIt()" /> &nbsp;<input class="btn btn-success"type="submit" />

</div>

</form> </div> </section>

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
<script>
</script>






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 20 '18 at 8:19

























answered Nov 20 '18 at 5:03









Bhargav AbotiBhargav Aboti

233110




233110













  • thank you Bhargava for code, when I am deleting one column values its 0 but i want to add two columns values please help me how to do

    – marton mar suri
    Nov 20 '18 at 6:39











  • Updated my Ans Please check @martonmarsuri

    – Bhargav Aboti
    Nov 20 '18 at 8:20











  • Thank you very much Bhargav Aboti

    – marton mar suri
    Nov 20 '18 at 9:46













  • You can accept the answer....

    – Bhargav Aboti
    Nov 20 '18 at 11:09



















  • thank you Bhargava for code, when I am deleting one column values its 0 but i want to add two columns values please help me how to do

    – marton mar suri
    Nov 20 '18 at 6:39











  • Updated my Ans Please check @martonmarsuri

    – Bhargav Aboti
    Nov 20 '18 at 8:20











  • Thank you very much Bhargav Aboti

    – marton mar suri
    Nov 20 '18 at 9:46













  • You can accept the answer....

    – Bhargav Aboti
    Nov 20 '18 at 11:09

















thank you Bhargava for code, when I am deleting one column values its 0 but i want to add two columns values please help me how to do

– marton mar suri
Nov 20 '18 at 6:39





thank you Bhargava for code, when I am deleting one column values its 0 but i want to add two columns values please help me how to do

– marton mar suri
Nov 20 '18 at 6:39













Updated my Ans Please check @martonmarsuri

– Bhargav Aboti
Nov 20 '18 at 8:20





Updated my Ans Please check @martonmarsuri

– Bhargav Aboti
Nov 20 '18 at 8:20













Thank you very much Bhargav Aboti

– marton mar suri
Nov 20 '18 at 9:46







Thank you very much Bhargav Aboti

– marton mar suri
Nov 20 '18 at 9:46















You can accept the answer....

– Bhargav Aboti
Nov 20 '18 at 11:09





You can accept the answer....

– Bhargav Aboti
Nov 20 '18 at 11:09













0














Here is a simple example on how to handle the input directly:






const $source = document.querySelector('#source');
const $result = document.querySelector('#result');

const typeHandler = function(e) {
$result.innerHTML = e.target.value; //Here you can handle the event, make your calculation and display the calculated data
}

$source.addEventListener('input', typeHandler) // register for oninput
$source.addEventListener('propertychange', typeHandler) // for IE8

<input id="source" />
<div id="result"></div>








share|improve this answer
























  • hi Olli it is did not working properly.can show to its work please.

    – marton mar suri
    Nov 20 '18 at 4:53
















0














Here is a simple example on how to handle the input directly:






const $source = document.querySelector('#source');
const $result = document.querySelector('#result');

const typeHandler = function(e) {
$result.innerHTML = e.target.value; //Here you can handle the event, make your calculation and display the calculated data
}

$source.addEventListener('input', typeHandler) // register for oninput
$source.addEventListener('propertychange', typeHandler) // for IE8

<input id="source" />
<div id="result"></div>








share|improve this answer
























  • hi Olli it is did not working properly.can show to its work please.

    – marton mar suri
    Nov 20 '18 at 4:53














0












0








0







Here is a simple example on how to handle the input directly:






const $source = document.querySelector('#source');
const $result = document.querySelector('#result');

const typeHandler = function(e) {
$result.innerHTML = e.target.value; //Here you can handle the event, make your calculation and display the calculated data
}

$source.addEventListener('input', typeHandler) // register for oninput
$source.addEventListener('propertychange', typeHandler) // for IE8

<input id="source" />
<div id="result"></div>








share|improve this answer













Here is a simple example on how to handle the input directly:






const $source = document.querySelector('#source');
const $result = document.querySelector('#result');

const typeHandler = function(e) {
$result.innerHTML = e.target.value; //Here you can handle the event, make your calculation and display the calculated data
}

$source.addEventListener('input', typeHandler) // register for oninput
$source.addEventListener('propertychange', typeHandler) // for IE8

<input id="source" />
<div id="result"></div>








const $source = document.querySelector('#source');
const $result = document.querySelector('#result');

const typeHandler = function(e) {
$result.innerHTML = e.target.value; //Here you can handle the event, make your calculation and display the calculated data
}

$source.addEventListener('input', typeHandler) // register for oninput
$source.addEventListener('propertychange', typeHandler) // for IE8

<input id="source" />
<div id="result"></div>





const $source = document.querySelector('#source');
const $result = document.querySelector('#result');

const typeHandler = function(e) {
$result.innerHTML = e.target.value; //Here you can handle the event, make your calculation and display the calculated data
}

$source.addEventListener('input', typeHandler) // register for oninput
$source.addEventListener('propertychange', typeHandler) // for IE8

<input id="source" />
<div id="result"></div>






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 16 '18 at 13:12









OlliOlli

14313




14313













  • hi Olli it is did not working properly.can show to its work please.

    – marton mar suri
    Nov 20 '18 at 4:53



















  • hi Olli it is did not working properly.can show to its work please.

    – marton mar suri
    Nov 20 '18 at 4:53

















hi Olli it is did not working properly.can show to its work please.

– marton mar suri
Nov 20 '18 at 4:53





hi Olli it is did not working properly.can show to its work please.

– marton mar suri
Nov 20 '18 at 4:53


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53338406%2fauto-billing-using-javascript%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Florida Star v. B. J. F.

Danny Elfman

Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues