johnnyg24 Posted February 26, 2009 Share Posted February 26, 2009 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 More sharing options...
jeffman Posted February 26, 2009 Share Posted February 26, 2009 Try this:newCell.appendChild(im); Link to comment Share on other sites More sharing options...
johnnyg24 Posted February 26, 2009 Author Share Posted February 26, 2009 Try this:newCell.appendChild(im);Your Awesome!! That works. Thank you.One other question, is there a way to set the height and width of the image? Link to comment Share on other sites More sharing options...
justsomeguy Posted February 26, 2009 Share Posted February 26, 2009 NO!! Give up now!!I mean yeah. Either one should work I think:im.setAttribute('width', 200);im.style.width = '200px'; Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.