SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Non-Member
    Join Date
    Jul 2005
    Posts
    606
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    equivalent of $$variable for php in javascript?

    anyone?

  2. #2
    SitePoint Wizard dreamscape's Avatar
    Join Date
    Aug 2005
    Posts
    1,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think you'll probably have to use plain ole eval() to do that. There's no shortcut in javascript that I know of.

    Code:
    var myVar = 'anotherVar';
    var anotherVar = new Object();
    
    var testMe = eval(myVar);
    alert(testMe);

  3. #3
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,789
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Don't use eval. Never use eval. It is almost never needed.

    Code:
    var myVar = 'anotherVar';
    var anotherVar = new Object();
    
    var testMe = window[myVar];
    alert(testMe);
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


Bookmarks

Posting Permissions

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