View Full Version : I get a Strange Null Error

07-16-2007, 07:49 AM
I get an error on line 6...which is if (iframe.src="news.php")

i get Error:'null' is null or not an object

function checkPage()
var iframe = document.getElementById('main');
var news = 'news';
if (iframe.src="news.php")


This code is used in an html page with an iframe with id="main"
here is the iframe

<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

<head><script type="text/javascript" src="script/checkpage.js"></script></head>

07-16-2007, 08:34 AM
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.

07-16-2007, 06:15 PM
how do you suggest i call checkPage? i call it on body onload

Philip M
07-16-2007, 07:37 PM
if (iframe.src == "news.php")

07-16-2007, 07:40 PM
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

07-17-2007, 03:23 AM
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..

<div id="nav-menu" align="center">
<div id="Content">
<iframe id="main" scrolling="no" frameborder="no" name="main" width="100%" src="news.php"></iframe>

i get error

Error: Object Required