Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.