PDA

View Full Version : Why do I get "is null or not an object"?


WindInMyHair
09-27-2002, 08:45 PM
Hey.

When I run this code I get an error that says "document.content" is null or not an object".

This page loads 4 frames. (banner, footer, menu and content). I want to set the content frame to a different page.

When it executes the setContent function it produces the error.

Can someone tell me why? (thanks in advance). I am sure that I am doing something dumb, but don't know what it is.





<html>
<head>
<script>

function setContent(name) {
document.content.location.href = name;
}

self.onload = setContent('page1.html');

</script>
</head>

<frameset rows="43,*,15">
<frame src="banner.html" name="banner" noresize>
<frameset cols="20%,*">
<frame src="menu.html" name="menu">
<frame src="welcome.html" name="content" >
</frameset>
<frame src="footer.html" name="footer" noresize>
</frameset>
</html>


Regards,
Greener than a mountain meadow (in springtime).

lpok
09-27-2002, 09:01 PM
The frame is not part of the document. Try using just "content.location.href" instead.

beetle
09-27-2002, 09:03 PM
I'd do it like this<html>
<head>
<script>

function setContent(name) {
document.frames['content'].location.href = name;
}


</script>
</head>

<frameset rows="43,*,15" onload="setContent('page1.html');">
<frame src="banner.html" name="banner" noresize>
<frameset cols="20%,*">
<frame src="menu.html" name="menu">
<frame src="welcome.html" name="content" >
</frameset>
<frame src="footer.html" name="footer" noresize>
</frameset>

</html>Because you can't send parameters to a function with the scripted onload assignment, because it is just that, an assignment, not an actual call to the function.

WindInMyHair
09-27-2002, 09:11 PM
lpok - that changed the error, but didn't work either. I got a 'content is undefined' error.

beetle - thanks. that works, but... I left out part of the code. What it is doing first is parsing the variables to get the new page name and then setting the content frame to that variable (not a literal string).

How can I set the page name (as a variable, instead of a string) using the onLoad event?

Thanks again.

ps. I am sure these are basic questions, but I just don't have the hang of this yet. :)

WindInMyHair
09-27-2002, 09:16 PM
Sorry. I answered my own dumb question.

<frameset rows="43,*,15" onload="setContent(variable);">


Thanks guys for your help.