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 11 of 11
  1. #1
    New Coder
    Join Date
    May 2004
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts

    how to create a table after the page have loaded?

    can i create a table after the page have loaded and put that table in a already created table? for example

    <a onClick='javaScript:somenamefunction(this)>click this to create table </a>

    function somenamefunction(counter)
    {
    document.writeln("<table>")
    document.writeln("<tr>")
    document.writeln("<td>")
    document.writeln("test")
    document.writeln("</td>")
    document.writeln("</tr>")
    document.writeln("</table>")
    }

    but how do i put this table into another table that have already being created?

  • #2
    Regular Coder
    Join Date
    Jun 2004
    Location
    underground
    Posts
    186
    Thanks
    0
    Thanked 0 Times in 0 Posts

  • #3
    New Coder
    Join Date
    May 2004
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts
    so nw i know how to make a table, how to make a table that go into a table when u onClick some text? that i dunno ...

  • #4
    Regular Coder
    Join Date
    Jun 2004
    Location
    underground
    Posts
    186
    Thanks
    0
    Thanked 0 Times in 0 Posts
    All DHTML and DOM methods for that are either described in the article, or linked to from it.

  • #5
    New Coder
    Join Date
    May 2004
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts

    hmmm

    u did read throught the thing right?

  • #6
    Regular Coder
    Join Date
    Jun 2004
    Location
    underground
    Posts
    186
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Right

    If you are looking for a literal explanation of: "how to make a table that go into a table when u onClick some text", that would be an unlikely find.
    Several methods are at your disposal, however.

  • #7
    New Coder
    Join Date
    May 2004
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts
    arhh, i think i din make my self clear at the first place, i'm a newbie when it come to javascript so i was hoping for some tutorial on this topic

  • #8
    Senior Coder
    Join Date
    Feb 2004
    Location
    Edinburgh
    Posts
    1,352
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by guowei1000
    i was hoping for some tutorial on this topic
    or else, you were hoping for someone to write the script for you

    the MSDN link above is one of the best places to look. and gives you the code you need. you just have to work out how to put it all together

  • #9
    New Coder
    Join Date
    May 2004
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts
    finally able to write out the coding !! YES! but nw faces new problem, i dunno how to toogle the style display... hmmmm heres the code if anyone is interested, Thanks for all ur help


    <html>
    <head>
    <script language ="JAVASCRIPT">
    var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
    xmlDoc.load("note.xml");
    var strContent =""
    var transfernode =""
    function TestChildren(nodes)
    {
    document.writeln("<table border = 1>");
    document.writeln("<tr>");
    document.writeln("<td>");
    document.writeln("<A onClick='javaScript:toogle_state(this)'><font color= red><IMG SRC='minus.gif'>"+ nodes.nodeName +"</font></A>");
    if (nodes.hasChildNodes)
    {
    for (var i=0; i < nodes.childNodes.length; i++)
    {
    document.writeln("<table border = 1>");
    document.writeln("<tr>");
    document.writeln("<td>");
    if (nodes.childNodes(i).hasChildNodes) // add toogle in
    {
    document.writeln("<font color= red><A onClick='javaScript:toogle_state(this)'><IMG SRC='minus.gif'>"+nodes.childNodes(i).nodeName +"</A></font>");
    writechildren(nodes.childNodes(i))
    }
    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(nodeCounter)
    {

    // Unfold the branch if it isn't visible
    alert(nodeCounter.childNodes(0).nodeName + nodeCounter.childNodes(1).data)
    if (nodeCounter.nextSibling.style.display == 'none')
    {

    // Change the image (if there is an image)
    if (nodeCounter.children.length > 0)
    {
    if (nodeCounter.children.item(0).tagName == "IMG")
    {
    nodeCounter.children.item(0).src = "minus.gif";
    }
    }
    nodeCounter.nextSibling.style.display = '';
    }
    // Collapse the branch if it IS visible
    else
    {
    // Change the image (if there is an image)
    if (nodeCounter.children.length > 0)
    {
    if (nodeCounter.children.item(0).tagName == "IMG")
    {
    nodeCounter.children.item(0).src = "plus.gif";
    }
    }

    nodeCounter.nextSibling.style.display = 'none';

    }
    }


    function writechildren(sianz)
    {
    if (sianz.hasChildNodes)
    {
    for (var i=0; i < sianz.childNodes.length; i++)
    {
    document.writeln("<table border = 1>");
    document.writeln("<tr>");
    document.writeln("<td>");

    if (sianz.childNodes(i).hasChildNodes) // add toogle in
    {

    if (sianz.childNodes(i).nodeName == "#text")
    {
    document.writeln("<font color= red><A onClick='javaScript:toogle_state(this)'><IMG SRC='minus.gif'>"+ sianz.childNodes(i).text + "</A></font>");
    writechildren(sianz.childNodes(i))
    }
    else
    {
    document.writeln("<font color= red><A onClick='javaScript:toogle_state(this)'><IMG SRC='minus.gif'> "+ sianz.childNodes(i).nodeName + "</A></font>");
    writechildren(sianz.childNodes(i))
    }

    }
    else
    {
    if (sianz.childNodes(i).nodeName == "#text")
    {
    document.writeln(sianz.childNodes(i).text);
    writechildren(sianz.childNodes(i))
    }
    else
    {
    document.writeln(sianz.childNodes(i).nodeName);
    writechildren(sianz.childNodes(i))
    }
    }

    document.writeln("</tr>");
    document.writeln("</td>");
    document.writeln("</table>");
    }
    }

    }
    function callReadXml()
    {
    root = xmlDoc.documentElement;
    TestChildren(root);
    }
    </script>
    </head>
    <body>
    <script type="text/javascript">
    callReadXml();
    </script>
    </body>
    </html>


    p.s my function toogle state function dun work and i dunno how to make it work hai~~

  • #10
    New Coder
    Join Date
    May 2004
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts
    sry for the double post, but i was wondering if anyone can help? i cant seem to be able to do the function toogle_state for the above code.Can anyone help? i cant seem to locate the child table and so wasnt able to change it style.display. can anyone help me by telling me hw to locate the child table?

  • #11
    New Coder
    Join Date
    May 2004
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yoyo, finally got it ! thanks for all ur help now i can do a table and toogle it state yes! now i just need to do it frames.... hmmmm


  •  

    Posting Permissions

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