funkyjunky Posted November 6, 2007 Share Posted November 6, 2007 Hello everyone.I copied this code out of a book because I wanted to make it my own!However it all doesnt seem to work!I have the following files:cameras.xsdcameras.xmlcameras.htmlcameras.js1.jpg2.pngThe Xml file has the deatails of the cameras.The Html files has tables with buttonsThe javascript performs the fucnctions the buttons are going to perform by refrencing the html.I dont know what the Xsd file does!if you go to http://edgeorgetest.110mb.com/FILENAME (replacing FILENAME with any of the aforementioned flies) you can see for your selfThe Html page doesnt seem to do what i want it too and im not sure why!Here is my javascript code // JavaScript Document Created By Ed Georgeif(!document.all)location="cameras.html";var xmlDoc=new ActiveXObject ("Microsoft.XMLDOM");xmlDoc.async="false";xmlDoc.load("cameras.xml");if (xmlDoc.parseError != 0){ var msg="<p><b>ERROR</b>"; msg+="<br/> Error In File: "+xmlDoc.parseError.url; msg+="<br/> Error On Line: "+xmlDoc.parseError.line; msg+="<br/> Error Code: "+xmlDoc.parseError.errorCode; msg+="<br/> Error Reason: "+xmlDoc.parseError.reason; document.write(msg+"</p>");}else if(xmlDoc.documentElement.hasChildNodes){ var makes=xmlDoc.getElementByTagName("make"); var models=xmlDoc.getElementByTagName("model"); var codes=xmlDoc.getElementByTagName("code"); var resolutions=xmlDoc.getElementByTagName("res"); var images=xmlDoc.getElementByTagName("img"); var prices=xmlDoc.getElementByTagName("price"); function getMake(i) {return makes.item(i) .text} function getModel(i) {return models.item(i) .text} function getCode(i) {return codes.item(i) .text} function getRes(i) {return resoloutions.item(i) .text} function getImg(i) {return images.item(i) .text} function getPrice(i) {return prices.item(i) .text} function showPix() { var list="<table width='390px' border='1px' cellspacing='0px'><tr>"; for(var i=0; i< makes.lenght; i++) { list+="<td>"+getMake(i)+"<br/> "+getModel(i)+"<br/>"; list+="<img src='"+getImg(i)+"'></td>"; if((i+1)%3==0)list+="</tr><tr>"; } list+="</tr></table>"; sho.innerHTML=list; } function range(str) { var list="<table width='390px' border='1px' cellspacing='0px' cellpadding='5px'>"; for(var i=0; i< makes.lenght; i++) { var condition= (str=="Over") ? (getPrice(i) > 500) : (getPrice(i) < 500); if (condition) { list+="<tr><td style='text-align:center'> <img src='"+getImg(i)+"'></td>"; list+="<td>"+getMake(i)+"<br/> "+getModel(i)+"<br/>"; list+=getCode(i)+"<br/>"+getRes(i)+"million pixels<br/>"; list+="<b>£"+getPrice(i)+"</b></td></tr>"; } } list+="</table>"; sho.innerHTML=list; } function listAll(str) { var list="<caption>"+str+" List</caption>"; list+="<table width='390px' border='1px' cellspacing='0px'>"; list+="<tr><th>Make</th></tr>"; for(var i=0; i< makes.lenght; i++) { list+=(((i+1)%2)==0) ? "<tr style='background:silver'>" : "<tr style='background:white'>"; list+="<td>"+getMake(i)+"</td>"; //editedabove^^ list+="<td>"+getModel(i)+"</td>"; if(str=="Code")list+="<td style='align:center'>"+getCode(i)+"</td>"; if(str=="Price")list+="<td style='align:center'>"+getPrice(i)+"</td>"; if(str=="Resolution")list+="<td style='align:center'>"+getRes(i)+" million pixels</td>"; list+="</tr>"; } list+="</table>"; sho.innerHTML=list; }} can any one see an obvious problem?I hope you can help.Ed x Link to comment Share on other sites More sharing options...
justsomeguy Posted November 6, 2007 Share Posted November 6, 2007 Have you used any Javascript debugging tools to check for errors? That's a lot easier then reading through the code looking for errors. Opera shows a Javascript error on line 59. It looks like you also misspelled length. Firebug shows the same syntax error as Opera. Link to comment Share on other sites More sharing options...
funkyjunky Posted November 6, 2007 Author Share Posted November 6, 2007 so i did!I have sorted the error on 59But the HTML page doesnt display the content.I click on the buttons and it says "error on page" in the corner.The message states: Line: xChar: 1Error: Object ExpectedURL:http://edgeorgetest.110mb.com/cameras.html (where x depends on which button i press!) Link to comment Share on other sites More sharing options...
aspnetguy Posted November 6, 2007 Share Posted November 6, 2007 that looks like an IE JS error message. you'll find quickly that IE doesn't give accurate (not even close) line numbers. Try it in Firefox or Opera to get more helpful error messages. Link to comment Share on other sites More sharing options...
funkyjunky Posted November 6, 2007 Author Share Posted November 6, 2007 It doesnt do anything in Opera.Just displays the buttons, when you click...nothing! Link to comment Share on other sites More sharing options...
Shonumi Posted November 6, 2007 Share Posted November 6, 2007 It doesnt do anything in Opera.Just displays the buttons, when you click...nothing!Then that's a positive sign there's an error. Unlike IE, FF and Opera have separate consoles that indicate JavaScript issues and they won't say anything when you come across them, at least not outright. Opera, the more comprehensive in my opinion, has it in Tools -> Advanced -> Error Console. You can specify HTML, JS or any other type of errors you want to see. Also, Opera is more descriptive in telling you what type of error and provides a segment of the offending code. Try that. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.