PDA

View Full Version : populate (not sequentally) an Image Array and after use innerHTML to appear on screen



leonidassavvides
04-09-2010, 10:08 AM
How I populate (not sequentally) an Image Array and after use innerHTML to appear on screen the images[properties: id,alt,H,W,src]???
On red below I get error in js ie8...

any tip?


function levelImgs(level) {
anyArray = new Array('cell11','cell12','cell13','cell14','cell15','cell16','cell21','cell22','cell23','cell24','cell25','cell26','cell31','cell32','cell33','cell34','cell35',' cell36','cell41','cell42','cell43','cell44','cell45','cell46','cell51','cell52','cell53','cell54','cell55','cell56','cell61','cell62','cell63','cell64','cell65' ,'cell66');
Aimgs= new Array(33);
if (level==1) {
var table = document.getElementById("puzzleGrid");
var cells = table.getElementsByTagName("td");
for (var i=0; i<cells.length; i++) {
testCellId=anyArray[i]; // 0-17
//testCellId2=anyArray[cells.length-i-1]; // 35-18

var testCell = document.getElementById(testCellId);
Aimgs[testCell.firstChild.alt]= new Image(69,69);
Aimgs[testCell.firstChild.alt].src=testCell.firstChild.src;
Aimgs[testCell.firstChild.alt].alt=testCell.firstChild.alt;
Aimgs[testCell.firstChild.alt].id="p"+testCell.firstChild.alt;
}

for (var i=0; i<cells.length; i++) {
var tCell = document.getElementById(anyArray[i]);
var imageObj=Aimgs[i];
tCell.removeChild;
tCell.innerHTML ="<img src='"+imageObj.src+"' alt='"+imageObj.alt+"' height='69' width='69' id='"+imageObj.id+"' />";
}