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 8 of 8
  1. #1
    New Coder
    Join Date
    Dec 2002
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Get Array element through New Variable

    I keep getting the error "undefinedArray is undefined" when I run this this block of code even though I am able to access the array element. I think it has to do with the way I'm accessing the array. Can you help?

    Code:
    function ClearMenu(RO,position) 
    { 
       var string = '<img src="./images/nav/WhiteTile.gif" width="1" height="1" border="0"></div>'; 
       var output = '<h3>' + eval(RO+'Array['+position+']') + '</h3>';

  • #2
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Obviously your problem lies with your defining of the array here: eval(RO+'Array['+position+']')

    But considering that you only posted a small snippet of the code and I do not know what the Array name is suppose to look like, all I can do is quess...

    Try this: eval(RO+Array[position])

    But then again, I would nver use eval....

    .....Willy

  • #3
    New Coder
    Join Date
    Dec 2002
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The array is:

    RO1Array = new Array("Tutoring: Grades 1-6", "Tutoring: Grades 7-12", "Drop-In Classes", "Books, Supplies Materials");

    I actually figured out the reason for the undefinedArray error. I was calling a function somewhere else in the script without passing the right arguments.
    Thank you for your help--can you suggest another function to use other than eval()? Why is it so evil?
    Last edited by sybaritic_life; 08-13-2004 at 10:29 PM.

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    The Planet Earth Code Poet: True
    Posts
    282
    Thanks
    0
    Thanked 1 Time in 1 Post
    Try this:

    var output = '<h3>' + window[RO+"Array"][position] + '</h3>';

  • #5
    New to the CF scene
    Join Date
    Aug 2004
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by JohnKrutsch
    Try this:

    var output = '<h3>' + window[RO+"Array"][position] + '</h3>';
    looks to me like it should be...

    var output = '<h3>' + window["RO"+RO+"Array"][position] + '</h3>';

  • #6
    Regular Coder
    Join Date
    Jun 2002
    Location
    The Planet Earth Code Poet: True
    Posts
    282
    Thanks
    0
    Thanked 1 Time in 1 Post
    That all depends on what the value of RO is. Based on previous posts it is suggested that the eval method worked but sybaritic_life was just looking for a way to do it without eval. If that was the case then the way I suggested will work just fine.

  • #7
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,032
    Thanks
    0
    Thanked 248 Times in 245 Posts
    Quote Originally Posted by sybaritic_life
    Why is it so evil?
    eval()...pros and cons

  • #8
    New Coder
    Join Date
    Dec 2002
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks all for very useful comments & shedding some light. window["RO"+RO+"Array"][position]works great.


  •  

    Posting Permissions

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