...

View Full Version : Passing parameter to eval



thewyzzard
07-10-2002, 11:25 PM
In a function, I am trying to pass the parameters value to an eval function, but it keeps coming back with an error because it won't pass the actual value of the parameter, rather the name itself.

Cloudski
07-11-2002, 12:10 AM
It might help to post your code, that way we can find the error in it....:)

premshree
07-11-2002, 02:37 PM
Try this :



function functionName(paramName)
{
eval('..........' + '["'+paramName+'"]' + '..........');
}


:thumbsup:

thewyzzard
07-11-2002, 03:06 PM
Here is the code:

function moveOnMenu(newMenu) {
if (MenuX < PosX) {
MenuX = MenuX + increment;
if (is_NS5up) {
document.getElementById('newMenu').style.left = MenuX+"px";
} else {
eval(Lq+'["'+newMenu+'"]'+Sq+'.left=MenuX');
}
setTimeout('moveOnMenu(newMenu)',speed);
}
}


After making the change as per Premshree, I now get an "expected identifier" error.

:confused:

premshree
07-12-2002, 01:57 PM
Try this:



function moveOnMenu(newMenu)
{
if (MenuX < PosX)
{
MenuX = MenuX + increment;
if (is_NS5up)
{
document.getElementById('newMenu').style.left = MenuX+"px";
}
else
{
eval(Lq + newMenu + Sq + '.left=MenuX');
}
setTimeout('moveOnMenu(newMenu)',speed);
}
}


I assume Lq and Sq in the above code must be defined previously.

thewyzzard
07-12-2002, 02:22 PM
I'm still getting an "expected identifier" error.

By the way:

Lq = "document.all"
Sq=".style"

The above declarations are part of some "cross-browser" code, but my browser version causes them to be equal to the above values.

premshree
07-13-2002, 10:10 AM
Hello, I have a similar code, this seems to work fine (its not cross-browser though) :



<script language="JavaScript">
var layerRef="document.all";
var styleSwitch=".style";

// SHOW MENU
function showLayer(layerName){
eval(layerRef+'["'+layerName+'"]'+
styleSwitch+'.visibility="visible"');
}

// HIDE MENU
function hideLayer(layerName){
eval(layerRef+'["'+layerName+'"]'+
styleSwitch+'.visibility="hidden"');
}
</script>

joh6nn
07-13-2002, 01:51 PM
if you're trying to use a cross browser way to reference objects and their styles, then this is the best there is:

http://www.xs4all.nl/~ppk/js/dhtmloptions.html

adios
07-14-2002, 01:25 AM
function moveOnMenu(newMenu)
{
if (MenuX < PosX)
{
MenuX = MenuX + increment;
if (is_NS5up)
{
document.getElementById(newMenu).style.left = MenuX+"px";
}
else
{
eval(Lq + newMenu + Sq + '.left=MenuX');
}
setTimeout('moveOnMenu('+newMenu+')',speed);
}
}

That last line might need to be:

setTimeout('moveOnMenu("'+newMenu+'")',speed);

Hard to tell when the literal quotes will be required.

thewyzzard
07-17-2002, 07:39 PM
Thanks to everybody who posted a reply to my problem. I used a combination of just about every suggestion to solve the issue.

Mostly, it was a lack of understanding on this newbie Javahead's part.

Thanks again and Peace!

The Wyzzard of West Falls
(a/k/a Bill):thumbsup:

The Wizzard
07-18-2002, 07:38 AM
Ahh... Imposter! ( thewyzzard )

hehe ;) :p :thumbsup:

thewyzzard
07-18-2002, 02:29 PM
:D Hey man, I've been using "The Wyzzard" for about 20 years now.

Besides, there's room for two of us here, isn't there?;)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum