how to add a JS code to a sql view list

rongame

Member
hi

I'm trying to add a js code to change the background color of a td based on a value. i created a js file named list_47.js the number is the id of the list respectively. i added a js list plugin and called the file. unfortunately it is not working. this is my code

thanks

Code:
var allTableCells = document.getElementsByTagName("td class");
for(var i = 0, max = allTableCells.length; i < max; i++) {
    var node = allTableCells[i];
    var currentVal = parseFloat(node.childNodes[0].nodeValue);
    if(currentVal != NaN){
        if (currentVal <0)
            node.style.backgroundColor = "red";
    }
    else if (currentVal != NaN) {
        if (currentVal >=1 && currentVal <=10  )
            node.style.backgroundColor = "yellow";
}
}
 
Try:
JavaScript:
var allTableCells = document.getElementsByTagName("td");console.log(allTableCells);
instead:
JavaScript:
var allTableCells = document.getElementsByTagName("td class");console.log(allTableCells);
 
JavaScript:
var allTableCells = jQuery(".fabrikDataContainer td");
//console.log(allTableCells);
for(var i = 0, max = allTableCells.length; i < max; i++) {
    var node = allTableCells[i];
    //console.log(node);
    var currentVal = parseFloat(node.textContent);
   // console.log(currentVal);
   
    if(currentVal != NaN){
        if (currentVal <0)
            node.style.backgroundColor = "red";
        if (currentVal >=1 && currentVal <=10  )
            node.style.backgroundColor = "yellow";
    }
}
Change this code for your needs.
 
hi thank you.

its working...

i wanted to customise this code further by selecting a particular column.

si i added a class to the element but its not working...

.stock-inc is my class

Code:
var allTableCells = jQuery(".fabrikDataContainer.stock-inc td");
//console.log(allTableCells);
for(var i = 0, max = allTableCells.length; i < max; i++) {
    var node = allTableCells[i];
    //console.log(node);
    var currentVal = parseFloat(node.textContent);
   // console.log(currentVal);
  
    if(currentVal != NaN){
        if (currentVal <0)
            node.style.backgroundColor = "red";
        if (currentVal >=1 && currentVal <=10  )
            node.style.backgroundColor = "yellow";
    }
}

thanks again
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top