Jump to content

Script Not Runnning In Iexplore


cesenna

Recommended Posts

Hi,I've got a W3School CD_catalog javascript example and I made some modification to change the table to a dropdown list, but the code is not running in IExplore and I ask for some help to fix it.Tks.SennaHere is the code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>CD_Catalog_dropdown</title><style>.box1 {	padding: 3px;	border-width: thin;	border-style: solid;	border-color: #CCCCCC #666666 #666666 #CCCCCC;	position: absolute;	left: 220px;	top: 18px;}</style><script type="text/javascript">var xmlDoc;if (window.XMLHttpRequest)  {  xhttp=new XMLHttpRequest();  }else // Internet Explorer 5/6  {  xhttp=new ActiveXObject("Microsoft.XMLHTTP");  }xhttp.open("GET","cd_catalog.xml",false);xhttp.send("");xmlDoc=xhttp.responseXML;var x=xmlDoc.getElementsByTagName("CD");function show(i){artist=(x[i].getElementsByTagName("ARTIST")[0].childNodes[0].nodeValue);title=(x[i].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue);year=(x[i].getElementsByTagName("YEAR")[0].childNodes[0].nodeValue);country=(x[i].getElementsByTagName("COUNTRY")[0].childNodes[0].nodeValue);company=(x[i].getElementsByTagName("COMPANY")[0].childNodes[0].nodeValue);price=(x[i].getElementsByTagName("PRICE")[0].childNodes[0].nodeValue);txt="Artist: "+artist+"<br />Title: "+title+"<br />Year: "+year+"<br />Country: "+country+"<br />Company: "+company+"<br />Price: "+price ;document.getElementById("show").innerHTML=txt;}</script></head><body><script type="text/javascript">document.write("<select>");for (var i=0;i<x.length;i++)  {   document.write("<option onclick='show(" + i + ")'>");  document.write(x[i].getElementsByTagName("ARTIST")[0].childNodes[0].nodeValue);  document.write("</option>");  }document.write("</select>");</script><div class="box1" id='show'>Click an artist to display the full album information.</div></body></html>

Link to comment
Share on other sites

Your system is unusual, but there is nothing incorrect about the plan, and you are using document.write() in one of the very few ways that it can be used correctly.Please be more specific when you say it does not run in IE. Does anything happen? Do you get any error messages at all? (You know how to find them, yes?)Have you tried placing alert statements in your code so you can figure out exactly where it terminates?I suppose the first thing to do is alert the value of xhttp.responseXML. If it is undefined, then IE thinks you sent your XML data incorrectly. With IE, it is usually a mime-type error, and can often by fixed by running this statement before sending your AJAX object:xhttp.overrideMimeType('text/xml');

Link to comment
Share on other sites

Your system is unusual, but there is nothing incorrect about the plan, and you are using document.write() in one of the very few ways that it can be used correctly.Please be more specific when you say it does not run in IE. Does anything happen? Do you get any error messages at all? (You know how to find them, yes?)Have you tried placing alert statements in your code so you can figure out exactly where it terminates?I suppose the first thing to do is alert the value of xhttp.responseXML. If it is undefined, then IE thinks you sent your XML data incorrectly. With IE, it is usually a mime-type error, and can often by fixed by running this statement before sending your AJAX object:xhttp.overrideMimeType('text/xml');
Link to comment
Share on other sites

Sorry by the empty reply, but the IE crash down when I was posting my reply.I was not clear when I said that the code was not running in the IE. In fact it is, but the dropdown list does not pass the argument to the "show(i)" function.I also tried your suggestion to insert the xhttp.overrideMimeType('text/xml') but does not work, and I got the message that "the object have no support to this property or method".

Link to comment
Share on other sites

I was not clear when I said that the code was not running in the IE. In fact it is, but the dropdown list does not pass the argument to the "show(i)" function.
Are you sure? If the XML object does not exist, you should not expect the function to run correctly. What makes you think the list fails to pass the argument?
I also tried your suggestion to insert the xhttp.overrideMimeType('text/xml') but does not work, and I got the message that "the object have no support to this property or method".
Does the message occur immediately after you try to call xhttp.overrideMimeType()? Or does it occur at some other time?Do your select options look correct? When you look at them, do they show the correct text?If you want to solve this thing, you really need to provide as much information as you can. We could spend a week on this thing, or we could do it in a day.
Link to comment
Share on other sites

Are you sure? If the XML object does not exist, you should not expect the function to run correctly. What makes you think the list fails to pass the argument?
No, I'm not sure. I am guessing due to the dropdown list are being built according to the XML file but when you click on a name in the list, the parameter is not sent by the xhttp.send("") object and the variable xmlDoc has no response.
Does the message occur immediately after you try to call xhttp.overrideMimeType()? Or does it occur at some other time?
The error message occur in the next step ('xmlDoc' is null or it is not an object).
Could you post a link to the page?
As I've said in my first post, I got this code from an W3School example at (http://www.w3schools.com/xml/tryit.asp?filename=tryxml_app) and changed the <table> tag for a <select> tag according to the following:
document.write("<table border='1'>");for (var i=0;i<x.length;i++)  {   document.write("<tr onclick='show(" + i + ")'>");  document.write("<td>");  document.write(x[i].getElementsByTagName("ARTIST")[0].childNodes[0].nodeValue);  document.write("</td><td>");  document.write(x[i].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue);  document.write("</td></tr>");  }document.write("</table>");

document.write("<select>");for (var i=0;i<x.length;i++)  {   document.write("<option onclick='show(" + i + ")'>");  document.write(x[i].getElementsByTagName("ARTIST")[0].childNodes[0].nodeValue);  document.write("</option>");  }document.write("</select>");

The first code runs either in Firefox and IExplore and the second one only in the Firefox

Link to comment
Share on other sites

Move the click event from the option element to the select element. It's probably better to use onchange for that instead of onclick.document.write("<select onchange=\"show(this.value);\">");then make sure to give each of your options a value:document.write("<option value=\"" + i + "\">");

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...