1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Variables are printed just once!!!

Discussion in 'JavaScript and AJAX' started by pietrom, Feb 2, 2007.

  1. pietrom

    pietrom New Member

    I have a really stupid problem I have not been able to solve (Firefox2) :
    :confused:

    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:
    <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!

    :(
     
  2. pradeep

    pradeep Team Leader

    Please put up the JavaScript code, otherwise it's not possible to isolate the bug.
     
  3. pietrom

    pietrom New Member

    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 a moderator: Feb 4, 2007
  4. pradeep

    pradeep Team Leader

    You cannot have 1 or more elements with the same id
     
  5. shabbir

    shabbir Administrator Staff Member

    Dont upload code in zipped format but keep the code in the posts so that its easy for other users to search.
     
  6. pietrom

    pietrom New Member

    > 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...
     

Share This Page