Javascript function variables being validated before function called by Internet Explorer

Posted by CodingIsAwesome on Stack Overflow See other posts from Stack Overflow or by CodingIsAwesome
Published on 2010-05-30T03:37:17Z Indexed on 2010/05/30 3:42 UTC
Read the original article Hit count: 313

When my page loads it calls the function like below:

<body onLoad='changeTDNodes()'>

And the code it calls is below:

function applyThresholds(myvalue, mycell) { 

var threshold = 10;

if (myvalue.innerHTML >= threshold)
{
//mycell.style.setAttribute('cssText','font-size:x-large;');
mycell.setAttribute('bgColor','red');
}
else
{
mycell.setAttribute('bgColor','green');
}
}
function changeTDNodes() {

// there can be many 'td' elements; just return the nth element 
var RepairVideo_cell_value = document.getElementsByTagName('B')[21];
var RepairVideo_cell = document.getElementsByTagName('td')[16];

var PPV_cell_value = document.getElementsByTagName('B')[6];
var PPV_cell = document.getElementsByTagName('td')[1];

var LeadRepair_cell_value = document.getElementsByTagName('B')[11];
var LeadRepair_cell = document.getElementsByTagName('td')[6];

var LeadTier_cell_value = document.getElementsByTagName('B')[16];
var LeadTier_cell = document.getElementsByTagName('td')[11];

var CHSI_cell_value = document.getElementsByTagName('B')[26];
var CHSI_cell = document.getElementsByTagName('td')[21];

var HN_cell_value = document.getElementsByTagName('B')[31];
var HN_cell = document.getElementsByTagName('td')[26];

var CDV_cell_value = document.getElementsByTagName('B')[36];
var CDV_cell = document.getElementsByTagName('td')[31];

var CommOps_cell_value = document.getElementsByTagName('B')[42];
var CommOps_cell = document.getElementsByTagName('td')[36];

applyThresholds(PPV_cell_value, PPV_cell);
applyThresholds(LeadRepair_cell_value, LeadRepair_cell);
applyThresholds(LeadTier_cell_value, LeadTier_cell);
applyThresholds(RepairVideo_cell_value, RepairVideo_cell);
applyThresholds(CHSI_cell_value, CHSI_cell);
applyThresholds(HN_cell_value, HN_cell);
applyThresholds(CDV_cell_value, CDV_cell);
applyThresholds(CommOps_cell_value, CommOps_cell);

}

Although the code executes succssfully, in the bottom corner of internet explorer the error shows as:

Line: 12 Char: 1 Error: 'innerHTML' is null or not an object Code: 0

Yet if I move the applyThresholds function below the changeTDNodes function, the changeTDNodes functions complains that there is no such thing as the applyThresholds function.

What am I doing wrong here?

Thanks for all your help!

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about internet-explorer