javascript: var is 'undefined' in mozilla, works on chrome

I cannot solve this problem, this function works well in chrome but in mozilla i get a "type error: rowTotal is undefined" in line "var rowValue = rowTotal.split('.').join('')"

Can somebody help me? haven't been able to figure it out mysel

function calculateTotal(){
    var table = document.getElementById("tablaListado");    
    var numFilas = table.getElementsByTagName("tr").length;
    var count = 0;
    var total = 0;
    for(var i=1;i<(numFilas-1);i++){
        if(document.getElementById("sum_"+i).checked == true){
            var rowTotal = document.getElementById("total_"+i).innerText;
            var rowValue = rowTotal.split('.').join('');
            total =  parseInt(rowValue) + total;
            count = count + 1;
        }
    }

    showDiv(total, count);
}

thanks in advance!

Answers:

Answer

.innerText is not supported by Firefox, but you can use .textContent instead. Unfortunately, .textContent is not supported by IE, so you need to test for it first.

You can use this function:

function getInnerText(elementID)
{
  if(typeOf(document.getElementById(elementID).innerText) != "undefined")
  {
    return document.getElementById(elementID).innerText;
  }
  else
  {
    return document.getElementById(elementID).textContent;
  }
}

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.