Go4Expert

Go4Expert (http://www.go4expert.com/)
-   JavaScript and AJAX (http://www.go4expert.com/forums/javascript/)
-   -   Variables are printed just once!!! (http://www.go4expert.com/forums/variables-printed-t2831/)

pietrom 2Feb2007 20:32

Variables are printed just once!!!
 
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 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 3Feb2007 10:43

Re: Variables are printed just once!!!
 
Please put up the JavaScript code, otherwise it's not possible to isolate the bug.

pietrom 3Feb2007 15:46

Re: Variables are printed just once!!!
 
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>


pradeep 3Feb2007 23:46

Re: Variables are printed just once!!!
 
You cannot have 1 or more elements with the same id

shabbir 4Feb2007 08:11

Re: Variables are printed just once!!!
 
Dont upload code in zipped format but keep the code in the posts so that its easy for other users to search.

pietrom 4Feb2007 18:55

Re: Variables are printed just once!!!
 
> 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...


All times are GMT +5.5. The time now is 19:43.