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 3 of 3
  1. #1
    New Coder
    Join Date
    Jul 2011
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How do you use value of variable as variable name?

    I have these lines:

    var ddArray=['holidayTypes','groupType','group_status'];
    for(var x in ddArray) eval(ddArray[x]=0);
    alert(holidayTypes);
    alert(groupTypes);
    alert(group_status);
    But it only alerts something like:

    object HTMLSelectElement

    Please help, thank you.

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,398
    Thanks
    12
    Thanked 570 Times in 563 Posts
    One important rule for posting questions in developer forums: First state (as exactly as possible) what you want to achieve, then show us what you already tried and last but not least give us a description of the problem/error.

    Your description is missing the first and third part.

  • #3
    Regular Coder
    Join Date
    Aug 2010
    Posts
    970
    Thanks
    19
    Thanked 212 Times in 210 Posts
    Quote Originally Posted by cartergarth View Post
    I have these lines:



    But it only alerts something like:




    Please help, thank you.
    Code:
    <html>
    <script>
    var ddArray=['holidayTypes','groupType','group_status'];
    for(i=ddArray.length;i--;) window[ddArray[i]]=0;
    alert(holidayTypes);
    alert(groupType);
    alert(group_status); 
    </script>
    <body >
    
    
    </body>


  •  

    Tags for this Thread

    Posting Permissions

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