I have an stock listing html table. Adding rows or deleting rows with this javascript.
<script>
function addRow(dataTable) {
"use strict";
var table = document.getElementById("dataTable");
var rowCount = table.rows.length;
if(rowCount < 20){
var row = table.insertRow(rowCount);
var colCount = table.rows[0].cells.length;
for(var i=0; i<colCount; i++) {
var newcell = row.insertCell(i);
newcell.innerHTML = table.rows[0].cells[i].innerHTML;}
}else{
alert("En fazla 20 satır ekleyebilirsiniz.");
}
}
function deleteRow(dataTable) {
"use strict";
var table = document.getElementById("dataTable");
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) {
if(rowCount <= 1) {
alert("Tüm satırları silemezsiniz.");
break;
}
table.deleteRow(i);
rowCount--;
i--;
}
}
}
</script>
And in each row i have select option which retrieves data from mysql database including stock ids.
When i select a stock from select option, getting price of from mysql table and showing in third td with ajax post.
<script type="text/javascript">
$(document).ready(function(){
$("#tek_ice_stok_id").on('change',function(){
var row = $(this).closest("tr");
var tek_ice_stok_id = row.find(".tek_ice_stok_id").val();
var tek_ice_birim_fiyat = row.find(".tek_ice_birim_fiyat").val();
var dataString = "tek_ice_stok_id="+tek_ice_stok_id;
$.ajax({
type: "POST",
url: "stok_fiyat_cek.php",
data: dataString,
success: function(result){
row.find("td:eq(3)").html(result);
}
});
});
})();
</script>
My first problem is when i add rows, the prices are all same in each rows price area. So i should do something and when i select 2nd or 3rd,etc select optons ajax should bring me those stocks prices.
Can anyone help me about this?
Thanks.
Searched for it many times but couldnt find exactly same.