Hello, I'm having some trouble.
I am making a request to an XML file that has six items within it.
Requesting and putting the information on the page is easy enough, I just can't get it to format the way I want.
Right now, it outputs like this:
But I want it to output something more like this:HTML Code:<table> <tr> <td onclick="displayMovieInfo(0)">Forbidden Planet (1956)</td> <td onclick="displayMovieInfo(1)">The Exorcist (1973)</td> <td onclick="displayMovieInfo(2)">The Day the Earth Stood Still (1951)</td> <td onclick="displayMovieInfo(3)">Rec (2007)</td> <td onclick="displayMovieInfo(4)">Dawn of the Dead (1978)</td> <td onclick="displayMovieInfo(5)">Black Christmas (1974)</td> </tr> </table>
Here is the JavaScript I'm using:HTML Code:<table> <tr> <td onclick="displayMovieInfo(0)">Forbidden Planet (1956)</td> <td onclick="displayMovieInfo(1)">The Exorcist (1973)</td> </tr> <tr> <td onclick="displayMovieInfo(2)">The Day the Earth Stood Still (1951)</td> <td onclick="displayMovieInfo(3)">Rec (2007)</td> </tr> <tr> <td onclick="displayMovieInfo(4)">Dawn of the Dead (1978)</td> <td onclick="displayMovieInfo(5)">Black Christmas (1974)</td> </tr> </table>
I know something has to go after:HTML Code:<script type="text/javascript"> if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.open("GET","movie_catalog.xml",false); xmlhttp.send(); xmlDoc=xmlhttp.responseXML; x=xmlDoc.getElementsByTagName("MOVIE"); function displayMovieInfo(i) { title=(x[i].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue); year=(x[i].getElementsByTagName("YEAR")[0].childNodes[0].nodeValue); format=(x[i].getElementsByTagName("FORMAT")[0].childNodes[0].nodeValue); txt="Title: "+title+"<br />Year: "+year+"<br />Format: "+format ; document.getElementById("showMovie").innerHTML=txt; } document.write("<table border='1'><tr>"); for (var i=0; i < x.length; i++) { document.write("<td onclick='displayMovieInfo(" + i + ")'>"); document.write(x[i].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue); document.write(" (" + x[i].getElementsByTagName("YEAR")[0].childNodes[0].nodeValue + ")"); document.write("</td>"); } document.write("</tr></table>"); </script>
for (var i=0; i < x.length; i++) {
to check when it reaches whatever column limit I wish to set; in the example output, 2.
But everything I've tried hasn't worked, I'm a real noob when it comes to JavaScript, so I was hoping some of you fine people could help me out.
And word on it would be greatly appreciated.![]()



Reply With Quote


Bookmarks