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 6 of 6
  1. #1
    New Coder
    Join Date
    Sep 2006
    Posts
    26
    Thanks
    3
    Thanked 0 Times in 0 Posts

    I get a Strange Null Error

    I get an error on line 6...which is if (iframe.src="news.php")

    Code:
    i get Error:'null' is null or not an object
    PHP Code:
    <!--
    function 
    checkPage()
    {
        var 
    iframe document.getElementById('main');
        var 
    news 'news';
        if (
    iframe.src="news.php")
        {
            
    document.write(news);
        }
        
    }
    //--> 
    This code is used in an html page with an iframe with id="main"
    here is the iframe
    PHP Code:
    <iframe id="main" onLoad="calcHeight();" scrolling="no" frameborder="no" name="main" width="100%"  src="news.php"></iframe
    calcHeight is a different javascript function in a different javascript file that works fine

    here is how i call the javascript...ill post it to make sure im not doing this one wrong
    PHP Code:
    <head><script type="text/javascript" src="script/checkpage.js"></script></head> 

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    How are you calling the checkPage function? Calling it before the page is finished loading will throw an error because the element with id="main" doesn't yet exist in the DOM.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    New Coder
    Join Date
    Sep 2006
    Posts
    26
    Thanks
    3
    Thanked 0 Times in 0 Posts
    how do you suggest i call checkPage? i call it on body onload
    Last edited by Alphamonkey; 07-16-2007 at 05:19 PM.

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,917
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    if (iframe.src == "news.php")

  • #5
    New Coder
    Join Date
    Sep 2006
    Posts
    26
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Philip M View Post
    if (iframe.src == "news.php")
    well that fixes a problem, but the problem that Aerospace_Eng was talking about is still there...unless this error is trying to trick me

    Error: Object Required

  • #6
    New Coder
    Join Date
    Sep 2006
    Posts
    26
    Thanks
    3
    Thanked 0 Times in 0 Posts
    so the new problem is....

    how do i perform a function inside of a div when that function checks a different element thats further down in the code?
    i have used body onload and it doesnt work

    the checkpage checks the src of iframe..
    Code:
    <div id="nav-menu" align="center">
    <script>checkPage();</script>
    </div>
    <div id="Content">
    <iframe id="main"  scrolling="no" frameborder="no" name="main" width="100%"  src="news.php"></iframe>
    </div>
    i get error
    Error: Object Required
    Last edited by Alphamonkey; 07-17-2007 at 02:33 AM.


  •  

    Posting Permissions

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