Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    New to the CF scene
    Join Date
    Jul 2002
    Location
    West Falls, NY (south of Buffalo)
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Passing parameter to eval

    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.

  • #2
    Regular Coder
    Join Date
    Jul 2002
    Location
    U.S. (Wish Japan though)
    Posts
    141
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It might help to post your code, that way we can find the error in it....

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    Mumbai, India
    Posts
    218
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try this :

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

  • #4
    New to the CF scene
    Join Date
    Jul 2002
    Location
    West Falls, NY (south of Buffalo)
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unexpected identifier

    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.


  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    Mumbai, India
    Posts
    218
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try this:

    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); 
     } 
    }
    I assume Lq and Sq in the above code must be defined previously.

  • #6
    New to the CF scene
    Join Date
    Jul 2002
    Location
    West Falls, NY (south of Buffalo)
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #7
    Regular Coder
    Join Date
    Jun 2002
    Location
    Mumbai, India
    Posts
    218
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hello, I have a similar code, this seems to work fine (its not cross-browser though) :

    Code:
    <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>

  • #8
    Senior Coder joh6nn's Avatar
    Join Date
    Jun 2002
    Location
    72° W. 48' 57" , 41° N. 32' 04"
    Posts
    1,887
    Thanks
    0
    Thanked 1 Time in 1 Post
    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
    bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

    i am a loser geek, crazy with an evil streak,
    yes i do believe there is a violent thing inside of me.

  • #9
    Senior Coder
    Join Date
    Jun 2002
    Posts
    1,404
    Thanks
    2
    Thanked 32 Times in 32 Posts
    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.
    Last edited by adios; 07-14-2002 at 02:40 AM.

  • #10
    New to the CF scene
    Join Date
    Jul 2002
    Location
    West Falls, NY (south of Buffalo)
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thanks to all

    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)

  • #11
    Regular Coder
    Join Date
    Jun 2002
    Location
    Lake Forest, CA
    Posts
    259
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ahh... Imposter! ( thewyzzard )

    hehe

  • #12
    New to the CF scene
    Join Date
    Jul 2002
    Location
    West Falls, NY (south of Buffalo)
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •