Hi all, this is my first post.
I have a little ajax assignment that works fine on mozilla firefox 2.0, but doesn't work at all on Internet Explorer 7. Apparently it has to do with the line where tempDiv element takes the value from xhr.responseTex t. The line that says: tempDiv.innerHT ML= xhr.responseTex t;. Apparently Internet Explorer 7 cuts off some tags. There goes my code:-
HTML:-
[HTML]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Addres s Book</title>
<link rel="stylesheet " rev="stylesheet " href="StyleShee t.css" />
<script src="addressScr ipt.js" language=javasc ript></script>
</head>
<body>
<h1>Address Book</h1>
<h2>By: Raef Kandeel</h2>
<b><font color=green>Ref erences: Visual QuickStart Guide JavaScript and Ajax for the Web, Sixth Edition, http://safari.oreilly. com/9781593271060/Iassignment_id1 4</font></b><br />
<table><td>
<select id="names" size=15></select></td>
<td><div><b><fo nt color=red>Click the Name to Display the Contact Info</font></b></div></td></table>
<p></p>
</body>
</html>
[/HTML]
Javascript:-
CSS:-
XML:-
[HTML]<?xml version="1.0" encoding="utf-8" ?>
<addressBook>
<person>
<name id="name1">Rae f Kandeel</name>
<address id="address1">o laya street</address>
<phone id="phone1">321 54451</phone>
<emailAddress id="emailAddres s1">****@hotmai l.com</emailAddress>
</person>
<person>
<name id="name2">Moha mmed Hassanein Amer</name>
<address id="address2">T a7'asosy Street</address>
<phone id="phone2">645 61215</phone>
<emailAddress id="emailAddres s2">****@gmail. com</emailAddress>
</person>
<person>
<name id="name3">Moha mmed Edoso2y</name>
<address id="address3">s hare3 enasr, egypt</address>
<phone id="phone3">016 2545265</phone>
<emailAddress id="emailAddres s3">****@gmail. com</emailAddress>
</person>
<person>
<name id="name4">Esha 3rany Ayoob</name>
<address id="address4">e l ma2atam</address>
<phone id="phone4">016 66688822</phone>
<emailAddress id="emailAddres s4">****@gmail. com</emailAddress>
</person>
</addressBook>[/HTML]
Thanks Guys
I have a little ajax assignment that works fine on mozilla firefox 2.0, but doesn't work at all on Internet Explorer 7. Apparently it has to do with the line where tempDiv element takes the value from xhr.responseTex t. The line that says: tempDiv.innerHT ML= xhr.responseTex t;. Apparently Internet Explorer 7 cuts off some tags. There goes my code:-
HTML:-
[HTML]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Addres s Book</title>
<link rel="stylesheet " rev="stylesheet " href="StyleShee t.css" />
<script src="addressScr ipt.js" language=javasc ript></script>
</head>
<body>
<h1>Address Book</h1>
<h2>By: Raef Kandeel</h2>
<b><font color=green>Ref erences: Visual QuickStart Guide JavaScript and Ajax for the Web, Sixth Edition, http://safari.oreilly. com/9781593271060/Iassignment_id1 4</font></b><br />
<table><td>
<select id="names" size=15></select></td>
<td><div><b><fo nt color=red>Click the Name to Display the Contact Info</font></b></div></td></table>
<p></p>
</body>
</html>
[/HTML]
Javascript:-
Code:
window.onload= initializeAJAX;
var xhr=false;
function initializeAJAX() {
if (window.XMLHttpRequest) {
xhr = new XMLHttpRequest();
}
else {
if (window.ActiveXObject) {
try {
xhr =new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {xhr = new ActiveXObject("Microsoft.XMLHTTP"); }
}
}
if (xhr) {
xhr.onreadystatechange = populateCombo;
xhr.open("GET", "./AddressBook.xml", true);
xhr.send(null);
}
else {
alert("Sorry, but I couldn't create an XMLHttpRequest");
}
}
function populateCombo () {
//create new temporary element
var tempDiv= createTempDiv();
var contacts=tempDiv.getElementsByTagName ("name");
var combo=document.getElementById ("names");
for (var i=0; i<contacts.length; i++) {
var newContact = document.createElement('option');
newContact.text = contacts[i].innerHTML;
try
{
combo.add(newContact,null); // standards compliant
}
catch(ex)
{
combo.add(newContact); // IE only
}
}
combo.onchange=displayDetails;
}
function displayDetails () {
var tempDiv= createTempDiv();
var contacts=tempDiv.getElementsByTagName ("*");
var divElement = document.getElementsByTagName ("div")[0];
var neededContact= this.options [this.selectedIndex].text;
//store elements in tag "p"
storeP (contacts);
var i=1;
while (document.getElementById ("name" +i)){
var name=document.getElementById ("name" +i).innerHTML;
var emailAddress=document.getElementById ("emailAddress" +i).innerHTML;
var phone=document.getElementById ("phone" +i).innerHTML;
var address=document.getElementById ("address" +i).innerHTML;
if (name==neededContact) {
var stringOutput="<b>Name: </b>";
stringOutput = stringOutput + name + "<br>";
stringOutput+="<b>Phone: </b>";
stringOutput = stringOutput + phone + "<br>";
stringOutput+="<b>Address: </b>";
stringOutput = stringOutput + address + "<br>";
stringOutput+="<b>E-mail Address: </b>";
stringOutput = stringOutput + emailAddress + "<br>";
divElement.innerHTML= stringOutput;
}
i++;
}
}
function createTempDiv() {
var tempDiv = document.createElement ("div");
if (xhr.readyState == 4) {
tempDiv.innerHTML= xhr.responseText;
}
return tempDiv;
}
function storeP (contacts) {
var paragraphNode=document.getElementsByTagName ("p")[0];
if (!paragraphNode.innerHTML) {
for (var i=0; i<contacts.length; i++) {
document.getElementsByTagName ("p")[0].appendChild ((contacts[i]).cloneNode(true));
}}
}
Code:
h1
{
text-align:center;
}
select
{
color:blue;
}
p
{
display:none;
}
td
{
vertical-align:top;
}
table
{
border:15px;
border-style:solid;
border-spacing:100px;
}
div
{
width:700px;
}
[HTML]<?xml version="1.0" encoding="utf-8" ?>
<addressBook>
<person>
<name id="name1">Rae f Kandeel</name>
<address id="address1">o laya street</address>
<phone id="phone1">321 54451</phone>
<emailAddress id="emailAddres s1">****@hotmai l.com</emailAddress>
</person>
<person>
<name id="name2">Moha mmed Hassanein Amer</name>
<address id="address2">T a7'asosy Street</address>
<phone id="phone2">645 61215</phone>
<emailAddress id="emailAddres s2">****@gmail. com</emailAddress>
</person>
<person>
<name id="name3">Moha mmed Edoso2y</name>
<address id="address3">s hare3 enasr, egypt</address>
<phone id="phone3">016 2545265</phone>
<emailAddress id="emailAddres s3">****@gmail. com</emailAddress>
</person>
<person>
<name id="name4">Esha 3rany Ayoob</name>
<address id="address4">e l ma2atam</address>
<phone id="phone4">016 66688822</phone>
<emailAddress id="emailAddres s4">****@gmail. com</emailAddress>
</person>
</addressBook>[/HTML]
Thanks Guys
Comment