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 2004
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts

    why the code wont call on the function toogle_state?

    Code:
    <html>
    <head>
    <script language ="JAVASCRIPT">
    var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
    xmlDoc.load("note.xml");
    
    function TestChildren(nodes)
    {
    document.writeln("<table border = 1>");
    document.writeln("<tr>");
    document.writeln("<td>");
    document.writeln(nodes.nodeName);
    
    if (nodes.hasChildNodes)
    {
    for (var i=0; i <=nodes.childNodes.length-1; i++)
    {
    document.writeln("<table border = 1>");
    document.writeln("<tr>");
    document.writeln("<td>");
    if (nodes.childNodes(i).hasChildNodes)
    {
    document.writeln("<font color= red><A onClick='javaScript:toogle_state(this)'>"+ nodes.childNodes(i).nodeName +"</A></font>");
    document.writeln("</tr>");
    document.writeln("</td>");
    document.writeln("</table>");
    }
    else 
    {
    document.writeln(nodes.childNodes(i).nodeName);
    document.writeln("</tr>");
    document.writeln("</td>");
    document.writeln("</table>");
    }
    
    }
    }
    
    
    document.writeln("</td>");
    document.writeln("</tr>");
    document.writeln("</table>");
    }
    
    function toogle_state(counter)
    {
    alert("hi")
    }
    
    
    function callReadXml()
    {
    root = xmlDoc.documentElement;
    TestChildren(root);
    }
    </script>
    </head>
    <body onLoad=callReadXml()>
    
    </body>
    </html>
    arhh, shouldnt the function toogle_state be call when i click?? What wrong with the code?
    Last edited by liorean; 06-11-2004 at 11:13 AM. Reason: [code]

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,968
    Thanks
    0
    Thanked 236 Times in 233 Posts
    If you execute document.write method AFTER the page has loaded, it will erase the current content and create a new document. So when the links are created, all your javascript functions are gone.

    The solution is to call callReadXml() AS the page is loading, not on onload.

    <body>
    <script type="text/javascript">
    callReadXml();
    </script>
    </body>

  • #3
    New Coder
    Join Date
    May 2004
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts
    :O thanks! its solved my problem!!


  •  

    Posting Permissions

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