Jump to content

cant get my table to display in function


welshy2013

Recommended Posts

i written a bit of code which would display a table of the selected data from my xml file but havent no luck. here my javascript function code;

 

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js" 
type="text/javascript"></script>
<script type="text/javascript">


function load_xml(){
var x=document.getElementById("mySelect").selectedIndex;
var y=document.getElementById("mySelect").options;


alert ("the selected index of the array is " +y[x].index+" value:"+y[x].text);


var check = y[x].text;


alert (check);


var xmlhttp;
var txt,xx,x,i;
if (window.XMLHttpRequest)
 {// code for IE7+, Firefox, Chrome, Opera, Safari
 xmlhttp=new XMLHttpRequest();
 }
else
 {// code for IE6, IE5
 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
 }
xmlhttp.onreadystatechange=function()
 {
 if (xmlhttp.readyState==4 && xmlhttp.status==200)
   {
   txt="<table border='1'><tr><th>Title</th><th>Artist</th></tr>";
   x=xmlhttp.responseXML.documentElement.getElementsByTagName("CD");
   for (i=0;i<x.length;i++)
     {
     txt=txt + "<tr>";
     xx=x[i].getElementsByTagName("TITLE");
       {
       try
         {
         txt=txt + "<td>" + xx[0].firstChild.nodeValue + "</td>";
         }
       catch (er)
         {
         txt=txt + "<td> </td>";
         }
       }
   xx=x[i].getElementsByTagName("ARTIST");
     {
       try
         {
         txt=txt + "<td>" + xx[0].firstChild.nodeValue + "</td>";
         }
       catch (er)
         {
         txt=txt + "<td> </td>";
         }
       }
     txt=txt + "</tr>";
     }
   txt=txt + "</table>";
   document.getElementById('CDTable').innerHTML=txt;
   }
 }
xmlhttp.open("GET","http://localhost/xampp/htdocs//xml"+y[x].text,true);
xmlhttp.send();
}

 

the alert part works when i call function which tells me what i selected in my selection box but no table is displaying

 

in the body part i got;

 

<body>
<div id = table>
</div
</body

 

where also a bit of my xml file;

 

 

<CATALOG>

<CD>

<TITLE>Empire Burlesque</TITLE>

<ARTIST>Bob Dylan</ARTIST>

<COUNTRY>USA</COUNTRY>

<COMPANY>Columbia</COMPANY>

<PRICE>10.90</PRICE>

<YEAR>1985</YEAR>

</CD>

 

been working on this for hours and i cant seem to fix the problem

Not sure if it's just typo when wriging it here, but your html should look like this:

<body>
<div id = "table">
</div>
</body>

 

Notice the quotes around the id and the ending '>' after the closing div and closing body tags

 

That's something I noticed right away so maybe that's causing drama's.

 

Denno

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.