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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    May 2005
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Document.write blanks current code

    This is frustrating me. Opening IE displays the following code fine. When I open a new window the code no longer works. All the HTML is overwritten with the first document.write statement. Tried with window tried without Please help.

    This code pulls XML from a web site then parses it into a dynamically created table built with javascript. The write table is not working correctly, other methods work fine. This code also locks up Fire Fox to where it doesn't stop loading the page.


    var req;
    var textColor;
    var linkColor;
    var columns;
    var tWidth;
    var bgcolor;


    function init () {
    if (window.XMLHttpRequest)
    req = new XMLHttpRequest();

    else if (window.ActiveXObject)
    req = new ActiveXObject("Microsoft.XMLHTTP");

    // req.open("GET", "http://127.0.0.1/patches/AJAX.xml", true);
    req.open("GET", "http://127.0.0.1/patches/affiliate_AJAX.cfm?Affiliate=1&Campaign=10", true);
    //req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    req.onreadystatechange = callback;

    req.send(null);
    }

    function callback() {
    if (req.readyState == 4) {
    if (req.status == 200) {
    // update the HTML DOM based on whether or not message is valid
    // alert('valid request' + req.status + req.readyState);
    parseMessage();

    // writeTable();
    writeTable();
    return true;

    }
    }

    }

    function parseMessage() {
    var message = req.responseXML.getElementsByTagName("fontcolor")[0];
    textColor = message.childNodes[0].nodeValue;

    message = req.responseXML.getElementsByTagName("linkcolor")[0];
    linkColor = message.childNodes[0].nodeValue;

    message = req.responseXML.getElementsByTagName("tablecols")[0];
    columns = message.childNodes[0].nodeValue;

    message = req.responseXML.getElementsByTagName("tablewidth")[0];
    tWidth = message.childNodes[0].nodeValue;

    message = req.responseXML.getElementsByTagName("bgcolor")[0];
    bgcolor = message.childNodes[0].nodeValue;

    }

    function writeTable() {

    window.document.writeln('<table border="0" cellspacing="10" width="' + tWidth + '" bgcolor="#' + bgcolor + '">');

    for (i=0; i<columns; i++) {

    if ((i % columns) == 0)
    window.document.writeln('<tr>');
    //body of each slot
    window.document.writeln('<td>');
    window.document.writeln('test');
    window.document.writeln('</td>');

    if ((i % columns) == (columns - 1))
    window.document.writeln('</tr>'); //end row if column limit is up

    }

    window.document.writeln('</table>');
    }

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    When you document.write after the page has loaded, all the contents will be overwritten. What you need is innerHTML or DOM methods createElement and appendChild. Search for those keywords here in CF and you'll find many results.


  •  

    Posting Permissions

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