?
Solved

mm_calljs function (performs an eval on an onClick)

Posted on 2004-08-30
4
Medium Priority
?
1,738 Views
Last Modified: 2008-01-09
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.
0
Comment
Question by:-Alexi-
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 33

Expert Comment

by:sajuks
ID: 11938917
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


0
 
LVL 33

Expert Comment

by:sajuks
ID: 11938925
In your case it is evaluating the output that is generated from the function small() .
0
 

Author Comment

by:-Alexi-
ID: 11938991
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.
0
 
LVL 33

Accepted Solution

by:
sajuks earned 753 total points
ID: 11939008
If small() doesnt have anything then wy do you still want to call it ?Can you post your function small() ?
The advantages of using EVAl are as stated above and if not required then there is really no reason why it needs to be called.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question