Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    May 2009
    Posts
    59
    Thanks
    1
    Thanked 0 Times in 0 Posts

    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>

  • #2
    Senior Coder ckeyrouz's Avatar
    Join Date
    Jun 2009
    Location
    Montreal, Canada
    Posts
    1,044
    Thanks
    5
    Thanked 179 Times in 179 Posts
    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.

  • #3
    New Coder
    Join Date
    May 2009
    Posts
    59
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •