Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-05-2009, 05:36 PM   PM User | #1
flint0131
New Coder

 
Join Date: May 2009
Posts: 59
Thanks: 1
Thanked 0 Times in 0 Posts
flint0131 is an unknown quantity at this point
Simple XML won't work on Firefox

It works 100% on IE, i dunno what's the problem with firefox.. It always says on Error Console that xmlObj is null. D:

Here's my Code : [ Halp me please?! ]

Code:
<html>
<head>
<title>Student Information - BSIT 2B Evening</title>
<script type="text/javascript">
function $(id) {
	var x = eval("document.getElementById(\""+ id +"\")");
	return x;
}
function gT(name,num) {
	xmlObj = xmlDoc.documentElement;
	var y = eval("xmlObj.getElementsByTagName(\""+ name +"\")["+ num +"].childNodes[0].nodeValue;");
	return y;
}
var xmlDoc;
var xmlObj;
	try {
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.load("students.xml");
		xmlDoc.async = true;
	} catch (e) {
		xmlDoc = new window.XMLHttpRequest();
		xmlDoc.open("GET", "students.xml", true);
		xmlDoc.send(null);
	}
function showInfo(num) {
xmlObj = xmlDoc.documentElement;
	if ( num == 1 ) {
		$("profile").innerHTML = 
		"<img src=\""+ gT('image','0') +"\" align=\"left\" />"+
		"Name : "+ gT('name','0') +"<br />"+
		"Age : "+ gT('age', '0') +"<br />"+
		"Location : "+ gT('location', '0') +"<br />";
	} else if ( num == 2 ) {
		$("profile").innerHTML = 
		"<img src=\""+ gT('image','1') +"\" align=\"left\" />"+
		"Name : "+ gT('name','1') +"<br />"+
		"Age : "+ gT('age', '1') +"<br />"+
		"Location : "+ gT('location', '1') +"<br />";
	} else if ( num == 3 ) {
		$("profile").innerHTML = 
		"<img src=\""+ gT('image','2') +"\" align=\"left\" />"+
		"Name : "+ gT('name','2') +"<br />"+
		"Age : "+ gT('age', '2') +"<br />"+
		"Location : "+ gT('location', '2') +"<br />";
	} else if ( num == 4 ) {
		$("profile").innerHTML = 
		"<img src=\""+ gT('image','3') +"\" align=\"left\" />"+
		"Name : "+ gT('name','3') +"<br />"+
		"Age : "+ gT('age', '3') +"<br />"+
		"Location : "+ gT('location', '3') +"<br />";
	} else if ( num == 5 ) {
		$("profile").innerHTML = 
		"<img src=\""+ gT('image','4') +"\" align=\"left\" />"+
		"Name : "+ gT('name','4') +"<br />"+
		"Age : "+ gT('age', '4') +"<br />"+
		"Location : "+ gT('location', '4') +"<br />";
	} else { return false; }
}
function clrscr() {
	$("profile").innerHTML = "";
}
</script>
</head>
<body>
<a href="javascript: void(0);" onmouseover="showInfo('1')" onmouseout="clrscr()">NAME HERE</a><br />
<a href="javascript: void(0);" onmouseover="showInfo('2')" onmouseout="clrscr()">NAME HERE</a><br />
<a href="javascript: void(0);" onmouseover="showInfo('3')" onmouseout="clrscr()">NAME HERE</a><br />
<a href="javascript: void(0);" onmouseover="showInfo('4')" onmouseout="clrscr()">NAME HERE</a><br />
<a href="javascript: void(0);" onmouseover="showInfo('5')" onmouseout="clrscr()">NAME HERE</a>
<div id="profile" style="position: absolute; left: 300px; top: 100px;"></div>
</body>
</html>
flint0131 is offline   Reply With Quote
Old 09-05-2009, 07:17 PM   PM User | #2
ckeyrouz
Senior Coder

 
ckeyrouz's Avatar
 
Join Date: Jun 2009
Location: Montreal, Canada
Posts: 1,044
Thanks: 5
Thanked 179 Times in 179 Posts
ckeyrouz is on a distinguished road
Maybe it is because of the documentElement try removing this line in the function gT:
Code:
xmlObj = xmlDoc.documentElement;
__________________
Software and cathedrals are much the same - first we build them, then we pray.
ckeyrouz is offline   Reply With Quote
Old 09-06-2009, 06:04 AM   PM User | #3
flint0131
New Coder

 
Join Date: May 2009
Posts: 59
Thanks: 1
Thanked 0 Times in 0 Posts
flint0131 is an unknown quantity at this point
I did remove it, still it won't work..

Anyway, I made a changes to the code.. it still works in IE, but in Firefox.. it won't..

Code:
<html>
<head>
<title>Student Information - BSIT 2B Evening</title>
<script type="text/javascript">
function $(id) {
	var x = eval("document.getElementById(\""+ id +"\")");
	return x;
}
function gT(name,num) {
	var y = eval("xmlObj.getElementsByTagName(\""+ name +"\")["+ num +"].childNodes[0].nodeValue;");
	return y;
}
var xmlDoc;
var xmlObj;
	try {
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.load("students.xml");
		xmlDoc.async = true;
	} catch (e) {
		xmlDoc = new window.XMLHttpRequest();
		xmlDoc.open("GET", "students.xml", true);
		xmlDoc.send(null);
	}
function showInfo(num) {
xmlObj = xmlDoc.documentElement;
		$("profile").innerHTML = 
		"<img src=\""+ gT('image',num) +"\" align=\"left\" />"+
		"Name : "+ gT('name',num) +"<br />"+
		"Age : "+ gT('age', num) +"<br />"+
		"Location : "+ gT('location', num) +"<br />";
}
function clrscr() {
	$("profile").innerHTML = "";
}
</script>
</head>
<body>
<a href="javascript: void(0);" onmouseover="showInfo(this.id)" onmouseout="clrscr()" id="0">Kevin Namuag</a><br />
<a href="javascript: void(0);" onmouseover="showInfo(this.id)" onmouseout="clrscr()" id="1">Lovable Lalaine Fabela</a><br />
<a href="javascript: void(0);" onmouseover="showInfo(this.id)" onmouseout="clrscr()" id="2">Bonifacio Opada</a><br />
<a href="javascript: void(0);" onmouseover="showInfo(this.id)" onmouseout="clrscr()" id="3">Marlou Camarillo</a><br />
<a href="javascript: void(0);" onmouseover="showInfo(this.id)" onmouseout="clrscr()" id="4">Marlon Mozo</a>
<div id="profile" style="position: absolute; left: 300px; top: 100px;"></div>
</body>
</html>
flint0131 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:42 AM.


Advertisement
Log in to turn off these ads.