PDA

View Full Version : status bar mouseover


avsgunnar
07-21-2003, 09:40 PM
I am trying to write a javascript that places a message in the status bar.

Here is an example:

function sthome()
{window.status = "Return to Homepage"; return true;}

function stoff(b)
{window.status = b; return true;}

In the HTML, then I do the following:

onMouseOver="ston('Homepage'); return true;" onMouseOut="stoff()"; return true;"

This script works fine ands does what its supposed to do.

QUESTION: Is there a way to include the return true commands that I have to put in the HTML into the script itself? I would rather have it look like this in the HTML....

onMouseOver="ston('Homepage');" onMouseOut="stoff()"


I got it to work once, thought I had it figured out, but forgot to save the changes before I started to rework the whole script. Now I can't remember how I did it.

Thanks for any input on this.

Roy Sinclair
07-21-2003, 11:35 PM
onMouseOver="return ston('Homepage');"return onMouseOut="stoff()"

avsgunnar
07-22-2003, 04:36 AM
Thanks, that will work.

Just for information purposes though, how can you make a javascript RETURN TRUE when you write the script itself? When I wrote it like I did above in my example, it just ignored it. (I had to put the return statement in the HTML.) Do I have a semicolon in the wrong place?

I used to just use a lot of javascript I found on the internet but started reading through some tutorials to learn how to write them myself in order to make them more custom for me.

cheesebagpipe
07-22-2003, 04:51 AM
A bit confused here...'JavaScripts' don't return anything: functions do. All functions return a value; the default is 'undefined'. How do you get a function to return a true value?

function bla() {
...........
...........
return true;
}

The problem you were having is: this -

onMouseOver="ston('Homepage');"

...contains a function, too. You can't see it but, trust me, it's there. Everything between the quotes becomes JS code, and the only way JS code can be stored for later use is within a function; that's what they're for. The browser 'wraps' HTML event handler strings inside an 'anonymous' function. Now you've got this:

Element.onmouseover = function() { ston('Homepage'); }

If your 'ston()' function returns true, the return value goes nowhere - it's trapped inside the wrapper function. So you unconditionally return it:

onMouseOver="return ston('Homepage');"

Now the value is passed to the end of the line, delivering the status write (arguable if this is still necessary, but why mess with tradition).

avsgunnar
07-22-2003, 05:17 AM
Ahhh... that's the explanation I needed. Now it makes sense to me.

Thanks again for all the help.