Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why my Table isn't shown ?

Status
Not open for further replies.

Targol

Technical User
Sep 13, 2002
908
FR
I have a div in an HTML page in witch I create a table that I fill with values from an XML file. Adding a msgbox at the end of the computing that displays my div innerHTML attribute give me everything allright but when displaying my page under IE6, my div is empty. Here is the code :

HTML page
Code:
<body onload=&quot;call ChargerXML()&quot;>
<div id=&quot;EnteteCircuits&quot; class=&quot;DivTop&quot; align=&quot;center&quot;>
</div>
</body>
Css (in case of ..)
Code:
.DivTop {
	border : solid 1px #000000;
	position : absolute;
	top : 25px;
	left : 5px;
	width : 990px;
	height : 100px;
	overflow : auto;
	display : block;
	background : #F1F1F1;
	z-index : 255;
}
Script
Code:
Const MAX_WIDTH = 950
Const LIB_WIDTH = 450

function ChargerXML()

  Set G_objXML = CreateObject(&quot;Microsoft.XMLDOM&quot;)
  G_objXML.async = False
  G_objXML.load (&quot;LanceurLight.XML&quot;)
  call ChargerCircuits()

end function
	
function ChargerCircuits()
  Set objRootNode = G_objXML.SelectSingleNode(&quot;//&quot; & XMLNOD_APPLI & &quot;/&quot; & XMLNOD_LSTCIRC)
  Set objDetailNode = objRootNode.SelectSingleNode(&quot;./&quot; & XMLNOD_DETAIL)

  Set objHtmDiv = document.getElementById(&quot;EnteteCircuits&quot;)
  objHtmDiv.innerHTML=&quot;&quot;
	
  Set objHtmTable = document.createElement(&quot;TABLE&quot;)
  objHtmTable.border=&quot;0px&quot;
  objHtmTable.cellspacing=&quot;0px&quot;
  objHtmTable.cellpadding=&quot;0px&quot;
  objHtmTable.width=MAX_WIDTH & &quot;px&quot;
  objHtmDiv.appendChild(objHtmTable)

  Set objHtmTr = document.createElement(&quot;TR&quot;)
  objHtmTr.height=&quot;100px&quot;
  objHtmTable.appendChild(objHtmTr)
	
  Set objHtmTd = document.createElement(&quot;TD&quot;)
  objHtmTd.style.width= LIB_WIDTH & &quot;px&quot;
  objHtmTd.align=&quot;left&quot;
  objHtmTd.innerHtml=&quot; &quot;
  objHtmTr.appendChild(objHtmTd)
	
  set objLstNodes = objDetailNode.SelectNodes(&quot;./&quot; & XMLNOD_CIRCUIT)
  G_NbCircuits = objLstNodes.length
  widthCircuits = (MAX_WIDTH - LIB_WIDTH ) / G_NbCircuits
  For idx = 0 To G_NbCircuits - 1
    Set objNode = objLstNodes.nextNode()
    idCirc = objNode.getAttribute(XMLATT_IDENT)
    coulCirc = objNode.getAttribute(XMLATT_COULEUR)

    Set objHtmTd = document.createElement(&quot;TD&quot;)
    objHtmTd.style.width= widthCircuits & &quot;px&quot;
    objHtmTd.align=&quot;center&quot;
    objHtmTd.bgcolor=coulCirc
    objHtmTd.innerHtml= idCirc
    objHtmTr.appendChild(objHtmTd)
  Next
  msgbox objHtmDiv.innerHtml,, &quot;objHtmDiv&quot;
end function
Water is not bad as long as it stays out human body ;-)
 
I found what was wrong so I write it here for your information : The problem was that when dynamically creating a table, you must do it this order :
1 -> Create TABLE element
2 -> Create TBODY element and append it to Table
3 -> Create TR element(s) and append it(them) to TBODY
4 -> Create TD element(s) and append it(them) to TR

I just forgot to create TBODY that's why my table didn't display.

Hope this will help some as TBODY tag is very often forgotten in tables.

Water is not bad as long as it stays out human body ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top