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 to the CF scene
    Join Date
    Jul 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Dynamic Table with HTML Cells

    Hi All,

    I tried to add links to open local xml files in browser in a dynamic table cells. I need help. I tried all ways but I think I miss something.
    I can open them without table just by document.write(xmlfile location).
    Here is my code. please help.

    function showResultsTable(searched, srchedname) {
    // get the reference for the body
    var mybody = document.getElementsByTagName("body")[0];

    // creates a <table> element and a <tbody> element
    mytable = document.createElement("table");
    mytable.setAttribute('id', 'resulttable');
    mytablebody = document.createElement("tbody");

    // creating all cells
    var mycurrent_cell = new Array();

    for(var j = 0; j < srchedname.length; j++) {
    // creates a <tr> element
    mycurrent_row = document.createElement("tr");

    mycurrent_cell[0] = document.createElement("td");
    currenttext = document.createTextNode(j);
    mycurrent_cell[0].appendChild(currenttext);
    mycurrent_row.appendChild(mycurrent_cell[0]);


    mycurrent_cell[1] = document.createElement("td");
    link = document.createElement("a");
    link.name = ""+srchedname[j]);
    link.href = "C:\\AAA\\TestCasesList.xml";
    mycurrent_cell[1].appendChild(link);
    mycurrent_row.appendChild(mycurrent_cell[1]);


    mycurrent_cell[2] = document.createElement("td");
    currenttext = document.createTextNode(searched[j]);
    mycurrent_cell[2].appendChild(currenttext);
    mycurrent_row.appendChild(mycurrent_cell[2]);

    // appends the row <tr> into <tbody>
    mytablebody.appendChild(mycurrent_row);
    }
    // appends <tbody> into <table>
    mytable.appendChild(mytablebody);
    // appends <table> into <body>
    mybody.appendChild(mytable);
    // sets the border attribute of mytable to 2;
    mytable.setAttribute("border", "2");

    }

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,200
    Thanks
    75
    Thanked 4,342 Times in 4,308 Posts
    DEBUG DEBUG DEBUG!!!!

    Use Firebug plugin with Firefox.

    You have AT LEAST one major error:
    Code:
    link.name = ""+srchedname[j])
    You have a ) but no ( in that line.

    There may be other errors. You'll never know unless you debug.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,200
    Thanks
    75
    Thanked 4,342 Times in 4,308 Posts
    I *think* this is what you were trying to achieve:
    Code:
    <html>
    <head>
    <script>
    function showResultsTable(searched, srchedname) {
        // get the reference for the body
        var mybody = document.getElementsByTagName("body")[0];
    
        // creates a <table> element and a <tbody> element
        var mytable = document.createElement("table");
        mytable.setAttribute('id', 'resulttable');
        var mytablebody = document.createElement("tbody");
    
        // creating all cells
        var mycurrent_cell = new Array();
        
        for(var j = 0; j < srchedname.length; j++) {
            // creates a <tr> element
            var mycurrent_row = document.createElement("tr"); 
            var cell;
    
            cell = document.createElement("td"); 
            var currenttext = document.createTextNode(j); 
            cell.appendChild(currenttext); 
            mycurrent_row.appendChild(cell);
    
            cell = document.createElement("td"); 
            link = document.createElement("a");
            link.name = srchedname[j];
            link.href = "C:\\AAA\\TestCasesList.xml";
            var currenttext = document.createTextNode(searched[j]); 
            link.appendChild(currenttext);
            cell.appendChild(link);
            mycurrent_row.appendChild(cell);
    
            // appends the row <tr> into <tbody>
            mytablebody.appendChild(mycurrent_row);
        }
        // appends <tbody> into <table>
        mytable.appendChild(mytablebody);
        // appends <table> into <body>
        mybody.appendChild(mytable);
        // sets the border attribute of mytable to 2;
        mytable.setAttribute("border", "2");
    
    } 
    </script>
    </head>
    <body>
    <form><input type=button value="click" onclick="showResultsTable(['abc','def','ghi'],['foo','bar','baz']);"/></form>
    </body>
    </html>
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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