Link to home
Start Free TrialLog in
Avatar of -Alexi-
-Alexi-

asked on

mm_calljs function (performs an eval on an onClick)

Hi,
I'm fixing up someones code and came across this function:

function mm_calljs(jsStr) { //v2.0
  return eval(jsStr);
}

It's called by the following:

<a href="help.htm#javascript_required" onclick="mm_calljs('javascript:small()'); return false;">

I can't find any reason for passing it through this function.  I'm thinking it could be for backwards capability.

I'm assuming it came from a macromedia editor.

What I'm looking for is a reason for why it is put there, and which piece of software/version it came from?

Thanks, Alexi.
Avatar of sajuks
sajuks

the code does come from MacroMedia's DreamWeaver Editor.

function mm_calljs(jsStr) { //v2.0
  return eval(jsStr);
}
The real power of the eval command is its ability to work with data that is not known at load time—for example, user-entered data.  EVAL takes any string that you provide and executes it returning a result, if one is applicable. You can use this to execute JavaScript where what you are being asked to execute is not known at load time
If we take the below example:

function MM_jumpMenu(targ,selObj,restore)
{
    EVAL(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
    if (restore) selObj.selectedIndex=0;
}


This code sets the location of the object specified by the targ parameter to that of the value attribute of the selObj drop-down; the other parameter simply resets the drop-down if set to true. The reason that EVAL is used here is that it allows the developer to provide the target for the function, which could be a variety of things, for example:

targ value - load the selected URL
Document - current window
Parent - parent document when using Frames/IFrames
newwin - A different window identified by newwin
parent.mainframe - a sibling Frame/Iframe identified by mainframe
Top - The top level item in the current window


In your case it is evaluating the output that is generated from the function small() .
Avatar of -Alexi-

ASKER

thanks, but small doesn't return anything and there is no user defined variables.  Is there any advantage to passing it through the mm_calljs function? as opposed to:

onClick="small(); return false;"

I can't see any immediate advantage, but because it has to comply with accessibility guidelines I guessed it might be for backwards compatibility.
ASKER CERTIFIED SOLUTION
Avatar of sajuks
sajuks

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial