Variables are printed just once!!!

pietrom's Avatar, Join Date: Feb 2007
Light Poster
I have a really stupid problem I have not been able to solve (Firefox2) :


I have an xhtml page that must load an xml file with JavaScript, extract same values and print them.
Everything goes in the right way, until I make the xhtml page print a value twice:

HTML Code:
<body onload="LoadXMLdata()">
   value = <span id="value" />            <!-- ok -->
   value = <span id="value" />            <!-- here no value is printed! -->
</body>
It must not be possible that when a variable is printed, it is automatically reset!

pradeep's Avatar, Join Date: Apr 2005
Team Leader
Please put up the JavaScript code, otherwise it's not possible to isolate the bug.
pietrom's Avatar, Join Date: Feb 2007
Light Poster
Here it is.

This is the output I to get on the browser (Firefox2):

time = 0.05
time =

This is the output I would like to get:

time = 0.05
time = 0.05

Thank you for any information.
OutputData.xml
Code:
<params>
	<time>0.05</time>
	<iterations>28</iterations>
	<error>1.26</error>
</params>
printTwice.xhtml
Code:
<?xml version="1.0" encoding="UTF-8"?>

<!-- printTwice.xhtml
	 Find out why when I print the same variable more than once, this is effectively printed the first time only.
	 -->

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html
	 xmlns="http://www.w3.org/1999/xhtml"
	 xmlns:ev="http://www.w3.org/2001/xml-events"
	 xmlns:xf="http://www.w3.org/2002/xforms"
	 xml:lang="en" lang="en"
	 >
	
	<head>
		<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
		
		<script type="text/javascript">
			
			var  time = 0.0, iterations = 0, error = 0.0
			
			function UpdateView()
			{
				window.location.reload()
			}
			
			function LoadXMLdata()
			{
				// Code for Mozilla, Firefox, Opera, etc.
				if (document.implementation)
				{
					if (document.implementation.createDocument)
					{
						xmlDoc = document.implementation.createDocument("","",null);
						xmlDoc.load("./outputData.xml");
						xmlDoc.onload = GetXMLdata;
					}
					else
						alert('I cannot handle this script with your browser');
				}
				// Code for IE
				else if (window.ActiveXObject)
				{
					xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
					xmlDoc.async = false;
					xmlDoc.load("./outputData.xml");
					GetXMLdata();
				}
				else
				{
					alert('I cannot handle this script with your browser');
				}
			}
			
			function GetXMLdata()
			{
				// params { time, iterations, error }
				document.getElementById("time").innerHTML = xmlDoc.getElementsByTagName("time")[0].childNodes[0].nodeValue;
				document.getElementById("iterations").innerHTML = xmlDoc.getElementsByTagName("iterations")[0].childNodes[0].nodeValue;
				document.getElementById("error").innerHTML = xmlDoc.getElementsByTagName("error")[0].childNodes[0].nodeValue;
			}
			
		</script>
		
	</head>
	
	<body onload="LoadXMLdata()">
		
		
		time = <span id="time" /><br />			<!-- ok -->
		
		time = <span id="time" /><br />			<!-- Why here the value is not printed??? -->
		
		
	</body>
	
</html>

Last edited by shabbir; 4Feb2007 at 08:10.. Reason: Dont upload code in zipped format.
pradeep's Avatar, Join Date: Apr 2005
Team Leader
You cannot have 1 or more elements with the same id
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Dont upload code in zipped format but keep the code in the posts so that its easy for other users to search.
pietrom's Avatar, Join Date: Feb 2007
Light Poster
> You cannot have 1 or more elements with the same id

All I have to do is to print a value (obtained from a file) twice on the same web page.
It *must* be possible somehow...