...

View Full Version : I get a Strange Null Error



Alphamonkey
07-16-2007, 06: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")
{
document.write(news);
}

}
//-->

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>

_Aerospace_Eng_
07-16-2007, 07: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.

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

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

Alphamonkey
07-16-2007, 06: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

Alphamonkey
07-17-2007, 02: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">
<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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum