开发者

firefoxs is almost crashing with this code. It seems to work but not really

window.onload = raknaUtMedelvarde;

function raknaUtMedelvarde(){

    var tabell = document.getElementById("temperaturtabell");
    var rader = tabell.getElementsByTagName("tr");

    for (var i = 0; i < rader.length; i++){
        var tabellceller = rader[i].getElementsByTagName("td");
        //alert(tabellceller.length);
       //räkna ut medelvärde
        var medel = medelVarde(tabellceller);
        //alert(medel);
        var medelText = document.createTextNode(medel);
        var medelElement = tabellceller [tabellceller.length - 1];
        medelElement.appendChild(medelText);


    }
}

function medelVarde(celler){
    var summa = 0;
    for (var i = 1; i < celler.length - 1; i++){

         var nuvarandeVarde = celler[i].firstChild.nodeValue;
         summa = summa + parseInt(nuvarandeVarde);
    }
    return summa / 5;
}
// code behind "visa värde" (show the value)
//I think here somewhre is the problem?

function hitta(){

    var varde = parseInt(document.getElementById("varde").value);
   var tabell = document.getElementById("temperaturtabell");
    var rader = tabell.getElementsByTagName("tr");

    for ( var i = 0; i < rader.length; i++){

        var tabellceller = rader[i].getElementsByTagName("td");
       // checkpoint to see is the values is >= then the enter value
        if(haVarde (varde, tabellceller))
           rader[i].className = "emp";


    }
}

// boolean method to check the value
function haVarde(varde, celler){
    var harVarde = false;
    var sum = 0;
    for (var i = 1; i = celler.length -1; i++){

        var nuvarandevarde = parseInt(celler[i].firstChild.nodeValue);
            if ( nuvarandevarde  >= varde)
         开发者_运维技巧   {
                harVarde = true;
                celler[i].className = "emptd";
            }
    }
    return harVarde;
}

Hello there!

Im writing this code. The momment I try to check the value with the total data inside the table. FF starts crashing sort of to say..I'm having problems dont know where pls have a look at the message: http://dl.dropbox.com/u/3632213/what.jpg ...mm ,mm can't understand the message...any suggestions more than welcome! :)


This line:

for (var i = 1; i = celler.length -1; i++){

will cause an infinite loop.

You probably meant <= ?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜