Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

mm_calljs function (performs an eval on an onClick)

Posted on 2004-08-30
4
Medium Priority
?
1,758 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

618 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