welshy2013 Posted February 6, 2013 Share Posted February 6, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/274115-cant-get-my-table-to-display-in-function/ Share on other sites More sharing options...
denno020 Posted February 9, 2013 Share Posted February 9, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/274115-cant-get-my-table-to-display-in-function/#findComment-1411404 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.