Jump to content

Hard Time Placing Img In Table With Javascript


johnnyg24

Recommended Posts

I am having a hard time placing an image into a new cell using javascript. The image is being brought over from xml and I am trying to use the function called "appendImgCell". This all works because if I use document.body.appendChild(im) it puts all the images in the body. I need them to be in the last column in my table. Any help would be great.function that is trying to place the picture in the appropriate cell:

function drawTextTable() {		 var newRow;				 deleteRows(document.getElementById("mainTableBody"));		 for (var i = 0; i < db.length; i++) {			newRow = document.getElementById("mainTableBody").insertRow(i);			appendCell(newRow, "Item", db[i].idNum);			appendCell(newRow, "Desc", db[i].desc);			appendCell(newRow, "Construction", db[i].constructionTXT);			appendCell(newRow, "Style", db[i].pStyleTXT);			appendCell(newRow, "Class", db[i].pClassTXT);			appendCell(newRow, "Confinement", db[i].confCodeTXT);			appendCell(newRow, "Book", db[i].bookTXT);			appendCell(newRow, "Book Number", db[i].book);			appendCell(newRow, "Color Number", db[i].pColorCode);			appendCell(newRow, "Color", db[i].pColorCodeTXT);			appendImgCell(newRow, "Image", db[i].skuImg);		 }		 	  }	   function appendImgCell(Trow, Cclass, sImg) {		 var newCell = Trow.insertCell(Trow.cells.length);		 newCell.className = Cclass;		 im = document.createElement("img");		 im.src = sImg;		 //document.body.appendChild(im); (this works but it's not what I need)		 newCell. = document.getElementById("mainTableBody").appendChild(im);		 //I think I need some kind of property to attatch to this elementObject "newCell" 	  }		  	  function appendCell(Trow, Cclass, txt) {		 var newCell = Trow.insertCell(Trow.cells.length);		 newCell.className = Cclass;		 newCell.innerHTML = txt;	  }

Table it is trying to put the picture in:

<table id="mainTable" border="1" cellpadding="4"> 		 <tr class="mainTableHead"> 		   <th>Id Number</th>		   <th>Descritption</th>		   <th>Construction</th>		   <th>Style</th>		   <th>Class</th>		   <th>Confinment Code</th>		   <th>Book Name</th>		   <th>Book Number</th>		   <th>Color Number</th>		   <th>Color Name</th>		   <th>Image</th>		 </tr> 		  		 <tbody id="mainTableBody"> 		 </tbody> 	  </table>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...