You might want to try this. If you have to cycle through document.getElementById
for each box every time you want to change their colors it can be very inefficient. The getRefs function below returns an array of all the references that you can manipulate directly. Run it once when the page loads and then it will be pretty easy to manage the elements provided you store the output in a global array.
Code:
function getRefs(str){ //str in your case would be 'REV'
var x, current, flag, ctr, ref = Array();
current = new String();
flag = true;
ctr = 1; //since you're starting at '01' rather than zero
while(flag){
flag = false;
current = ctr + '';
if(current.length == 1){
current = '0' + current;
}
current = str + current;
alert(current);
x = document.getElementById(current);
if(x != (null || undefined)){
ref.push(x);
ctr++;
flag = true;
}
}
return ref;
}
window.onload=function(){
var z = getRefs('REV');
for( var i = 0; i < z.length; i++){
z[i].style.backgroundColor = "red";
}
}
Note though that the chain must be continuous. If you have a "REV12" and a "REV14" but no "REV13" the function won't map anything after the gap.
Bookmarks