First of all, you should ALWAYS begin your HTML files with a doctype.
Your JavaScript should really be in a separate file that is linked in with something like this before the </body> tag:
Code:
<script type="text/javascript" src="js/index.js"></script>
with all your JavaScript being put in the file "index.js" in a "js" subdirectory.
Second of all, I made a little demonstration snippet using JSFiddle, which can be found here:
http://jsfiddle.net/ianonavy/cfHpd/
I hope this helps. Continue to post if you have further questions.