kbjradmin
New Member
- Messages
- 512
- Reaction score
- 2
- Points
- 0
i'm trying to make a page that uses javascript to change the content in the main area of the page. i wrote this function:
but it keeps returning the error 'source is null'. i can't figure out why the source would be null. the function changeContent is called on page load with the string "home" for value.
Here's the markup if it helps:
please help.
Code:
function changeContent( value )
{
var content = document.getElementById("content");
var source = document.getElementById(value);
content.innerHTML = ( source.defaultHTML || source.innerHTML );
if ( ! source.defaultHTML )
{
source.defaultHTML = source.innerHTML;
}
source.innerHTML = "";
}
Here's the markup if it helps:
HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<?php include('config.php'); ?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!--Data Tags-->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="en-us" />
<title>PseudoFrame Template</title>
<!--File Includes-->
<!--Cascading StyleSheets-->
<link rel="stylesheet" type="text/css" href="style.css" />
<!--JavaScript-->
<script type="text/javascript" src="pseudoframe.js"></script>
</head>
<body>
<div id="header">
</div>
<div id="menu">
<ul>
<li><a href="#home" rel="frame">Home</a></li>
<li><a href="#about" rel="frame">About</a></li>
<li><a href="#contact" rel="frame">Contact Us</a></li>
<li><a href="#affiliates" rel="frame">Affiliates</a></li>
</ul>
</div>
<div id="content">
<!--
Content is dynamically inserted here based on the current page.
-->
</div>
<div id="footer">
</div>
<!--
START PAGE CONTENT DIVS
-->
<div id="home" class="contents">
<h1>Home</h1>
</div>
<div id="about" class="contents">
<h1>About</h1>
</div>
<div id="contact" class="contents">
<h1>Contact Us</h1>
</div>
<div id="affiliates" class="contents">
<h1>Affiliates</h1>
</div>
<!--
END PAGE CONTENT DIVS
-->
</body>
</html>
please help.
Last edited: