I have a piece of code where I am calling my server to fetch some values and update the table if that value isn't present there. After the updation, I want the user to be notified of the row where the value was updated, by making it's cell value bold for n seconds.
var table=document.getElementById("employee_details");
var jsonString = JSON.stringify(array);
$.ajax({
url: '/server.php',
type: 'POST',
data: {"input":"calculate_charges",
data:jsonString},
cache: false,
success:function(response){
const arr3=JSON.parse(response);
for(var i=0; i<arr3.length; i ){
if(table.rows[i 1].cells.item(10).innerHTML!=arr3[i][2]){
table.rows[i 1].scrollIntoView({
behavior: 'smooth',
block: 'center'
});
table.rows[i 1].cells.item(10).innerHTML=arr3[i][2];
setTimeout(function(){
table.rows[i 1].cells.item(10).style.fontWeight = "500";
},7000);
setTimeout(function(){
table.rows[i 1].cells.item(10).style.fontWeight = "900";
},4000);
}
}
}
complete:function(){}
});
Upon executing the code, I keep getting this error in the console:
Uncaught TypeError: Cannot read properties of undefined (reading 'cells')
And the cell item doesn't get bold. How do I fix this issue?
CodePudding user response:
Use let in for loop:
for(let i=0; i<arr3.length; i ){
About let: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let