Solved

mm_calljs function (performs an eval on an onClick)

Posted on 2004-08-30
4
1,726 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 251 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

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

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

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
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…

707 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