[thelist] DW code - why "return XXX" within onLoad?

jeff jeff at members.evolt.org
Fri Dec 29 16:22:08 CST 2000


david,

:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: From: David Prowak
:
: Why the return document.MM_returnValue?  I
: thought the return used in this manner only
: made a difference when used with the onClick
: event handler.
:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

the return statement is kind of an odd little beasty.  it has several uses.
the first, and most obvious is to return a value from a function to whatever
called that function.  like this:

function addNumbers(num1, num2)
{
  sum = parseInt(num1) + parseInt(num2);
  return sum;
}

alert(addNumbers(2,2));

what happens in the alert() is the addNumbers() function is called.  this
function takes two arguments - the two numbers to be added together.  it
forces the arguments to numbers and then adds them together, storing that
value in a variable called sum.  then, it returns that value and the result
is displayed in the alert().

the other use is to affect the behavior of event handlers.  some event
handlers can except a boolean - true or false - return statement and their
execution will be based on the boolean.  for example, if you return false in
the onSubmit event handler of the <form> tag, the form will not submit.  it
overrides the forms default behavior of submitting.  you can return false in
the onClick event handler of a button <input>, canceling the click of the
button.  where it gets confusing is with the onMouseover event handler of
the <a> tag.  the default behavior of the <a> tag is to display the value of
the href attribute.  if you don't tell the browser you want to override that
behavior, setting the window.status will have no effect.  the way you do
this is by returning true after trying to set it in the onMouseover.  this
tells the browser to use the window.status and not execute it's default
behavior.

so, in a roundabout way i'm trying to tell you that macromedia is returning
a boolean of true to the onMouseover event handler to override the browser's
default behavior of displaying the value of the href attribute and tell it
to display the status text instead.

good luck,

.jeff

name://jeff.howden
game://web.development
http://www.evolt.org/
mailto:jeff at members.evolt.org





More information about the thelist mailing list