• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

can't display a table in a div...

 
Ranch Hand
Posts: 365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to build a simple table and render it in a div but all I get is:
[object HTMLTableElement]

and the contents displayed at the bottom of the page:

1) code to generate table:

var table = document.createElement("table");
document.body.appendChild(table);
var keys = map.keySet();
for (i=0; i<keys.length; i++) {
// alert(map.get(keys[i]));
var row = document.createElement("tr");
//employee name
var td1 = document.createElement("td");
var tdText = document.createTextNode(map.get(keys[i]));
td1.appendChild(tdText);
row.appendChild(td1);
//modify radio button
var td2 = document.createElement("td");
var rdoName = "radio_" + keys[i];
var rdo = document.createElement("input");
rdo.type="radio";
rdo.id = rdoName;
rdo.name = 'rdoModify';
rdo.value = rdoName;
td2.appendChild(rdo);
row.appendChild(td2);
//delete check box
var td3 = document.createElement("td");
var chkName = "chk_" + keys[i];
var chk = document.createElement("input");
chk.type="checkbox";
chk.id = chkName;
chk.name = chkName;
chk.value = chkName;
td3.appendChild(chk);
row.appendChild(td3);
table.appendChild(row);
}
//attach form to div
var el = $('searchResults');
el.innerHTML = table;
Element.show(el);
}

2) the table is simply inserted into a div....

any help greatly appreciated
thanks
max
 
Sheriff
Posts: 67645
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

el.innerHTML = table;



You can't mix innerHTML and DOm manipulation. Use one or the other.

When you build up the elements in a DOM (as you are doing), you must use DOM methods to attached the new elements to the page DOM.
[ June 18, 2007: Message edited by: Bear Bibeault ]
 
Max Tomlinson
Ranch Hand
Posts: 365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ah yes...

div.appendChild(table)

works great!

thanks for the quick reply

Max
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Adding to what bear said.

use appendChild like the code does for the table.

Setting innerHTML requires a string and not an object.

Eric
 
Run away! Run away! Here, take this tiny ad with you:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic