Topic: Beginner onmouse java question with code

the onmouseover works but the onmouseout does'nt , Any ideas as to whats wrong?  Thanks.

<html>
<head>
<script type="text/javascript">
function mouseOver()
{
document.write("hello!!");
}
function mouseOut()
{
document.write("goodbye!!!");
}
</script>
</head>

<body>

<a  onmouseover="mouseOver()" onmouseout="mouseOut()">
Point your mouse here!
</a>
</body>
</html>

Vote up Vote down

Re: Beginner onmouse java question with code

Just a technicality, but it can cause confusion.

This is JavaScript (JS) - it is a scripting language from Netscape.

Java is a Programming language from Sun Microsystems.

They are two different critters.

Vote up Vote down

Re: Beginner onmouse java question with code

document.write() is deprecated and is poor form.  It works by immediately inserting text into the document while it is still being rendered by the browser - in this case, you're calling it after the document is loaded, so it ha nowhere to write to.

Try this:

function mouseOver()
{
alert("hello!!");
}
function mouseOut()
{
alert("goodbye!!!");
}

That should give you a popup when you go in and out of the area.

Vote up Vote down

Re: Beginner onmouse java question with code

thanks Iwsimon,  you clarified to me that I had the right idea but the "wrong" code .
I thought I had left out a ";" or something else ... more learning to do
Would this problem have showed up if I used a debugger ?
Thanks again

Vote up Vote down

Re: Beginner onmouse java question with code

What browser are you using to test in?  If you're using IE, I would strongly suggest that you download Firefox, and use Firebug for Javascript debugging.  Its error messages are much, much better than IE's.

This would not have shown up though.  A debugger can only tell you when you've made a syntax error.  This is a logic error - you're writing to a document that is already rendered. 

Do you have past experience programming?  If not, I would actually suggest learning PHP before learning Javascript.  PHP is more "traditional" and has better documentation.  A lot of people, including people who write tutorials, write very poor javascript.

Vote up Vote down