I'm familiar with HTML and CSS, and have now started to learn PHP without running into any trouble, but I want to add Javascript to my knowledge. I tried a long time ago, and failed, for the same reason I'm failing now. Code that looks logical to me is not logical in Javascript. Anything I try to make on my own always results in some kind of error, even if it appears to make sense to my warped brain.
What I'm trying to do now should be fairly simple. I'm trying to create a test page with a navbar and a set of links. When the user hovers over the links, the text should change to a discription of that link. I have altered my code a great deal, and have at least accomplished creating the discription (even if the CSS for it is in serious need of adjustment). However, no matter how many different things I try, I cannot get the discription to actually change. Firefox's Javascript console will either give me an error, or nothing will happen at all.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html> <!--HTML Transitional Javascript Test Page-->
<!--Header Information-->
<head>
<!--Page's Title-->
<title>
Test Page
</title>
<!--CSS Styling Information-->
<style>
/*Class Specific Styling Information*/
div#navbar
{
background-color: #00FF00;
position: absolute;
top: 0px;
left: 0px;
width: 100%;
}
div#navLinks
{
float: left;
}
div#linkDescriptions
{
background-color: #FFFF88;
margin: 10px 10px 10px 10px;
width: 100%;
}
</style>
<!--Scripting Information-->
<script type="text/javascript">
//Create the Link Discriptions div (Done using Javascript so that it doesn't appear with Javascript disabled).
function creatediscription()
{
var navbar = document.getElementById('navbar')
var linkDescriptions = document.createElement('div');
linkDescriptions.id = "linkDescriptions";
var linkDescriptions_textNode = document.createTextNode('Hover over a menu item for the discription.');
linkDescriptions.appendChild(linkDescriptions_textNode);
navbar.appendChild(linkDescriptions);
}
function changetext()
{{
linkDescriptions_textNode.nodeValue = 'Test';
alert('that aint it');
}}
</script>
</head>
<!--Body Information-->
<body onload="creatediscription();">
<div id="navbar">
<div id="navLinks">
<p>
<a href="#" onmouseover="changetext();">Main</a>
</p>
</div>
</div>
</body>
</html>
Despite having syntax highlighting, there must be something seriously wrong in here, because on the second function, I got an error saying there was a missing curly brace even when there was one. So I added a second one, which resulted in a complaint about a missing end brace. After adding a second brace, the error went away, so now I'm stuck with a rather rediculous double-bracketed function.
Note that the alert() is there because I was using it to debug to see if the function was even being called at all. It looks like it isn't, although considering that I have to put two brackets around it to avoid errors, that's not surprising.
I've been puzzling over this code for 2 and a half days now, and I'm ready to call it quits again. Can someone help?