Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: "null 2"  (Read 3831 times)

0 Members and 1 Guest are viewing this topic.

Bannana97

    Topic Starter


    Intermediate
  • Owner of HerbertsWorld Corporation
    "null 2"
    « on: July 20, 2009, 10:35:00 AM »
    For some reason, document.getElementById("D1") is returning null... And it's clearly on the page..

    Code: [Select]
    <iframe id="D1" style="width:100px; height:100px; border:1px black solid; display:none;" src="Get.php?ID=1">
    </iframe>
    <div id="ReadURL" name="ReadURL">
    <?php
    $ID 
    $_GET['ID'];
    $user $_COOKIE['usern'];
    if(!
    $user) {
    $user "Guest";
    }
    if(
    file_exists("Chat/$ID.php")) {

    }
    else {
    $A fopen("Chat/$ID.php""w");
    fwrite($A"<script type=\"text/javascript\">
    function reload(t) {
    if(!t) {
    if(!document.getElementById('D1')) { alert('null 2'); return false; }
    document.getElementById('D1').src = document.getElementById('D1').src; // D1 is an IFrame.
    setTimeout('reload(\'true\')', 1000);
    }
    else {
    if(!document.getElementById('D1')) { alert('null 1'); return false; }
    if(document.getElementById('D1').document.getElementById('ReadURL').innerHTML != document.getElementById('ReadURL').innerHTML) {
    alert('false');
    window.location.reload(true);
    }
    else {
    setTimeout('reload()', 1000);
    }
    }
    }
    setTimeout('reload()', 2500);
    </script>Welcome. To get started, type something in the chat box below."
    );
    }
    echo 
    file_get_contents("Chat/$ID.php");
    ?>


    </div>
    Thanks
    Bannana97

    Rob Pomeroy



      Prodigy

    • Systems Architect
    • Thanked: 124
      • Me
    • Experience: Expert
    • OS: Other
    Re: "null 2"
    « Reply #1 on: July 20, 2009, 03:58:57 PM »
    What is this line supposed to do?

    Code: [Select]
    document.getElementById('D1').src = document.getElementById('D1').src;
    And:

    Code: [Select]
    !document.getElementById('D1')
    Have you checked the spec for getElementById()?  Can you negate it?

    I have to say once more, the javascript prototype library makes this kind of stuff much easier.  "$('id')" instead of "document.getElementById('id')".  Nice.  http://prototypejs.org/

    Also, using the debug console of the Web Developer plugin for Firefox is a lifesaver.
    Only able to visit the forums sporadically, sorry.

    Geek & Dummy - honest news, reviews and howtos