SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Variables help

  1. #1
    SitePoint Addict
    Join Date
    May 2007
    Posts
    242
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Variables help

    Hello. Is it possible to create a variable whose name is another variable value.

    var pogo="newo";
    Above variable I will use I need to create a new variable named newo and assign it some other value. How can I get variable values and assign it as names for other ones?

    Thanks in advance.

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,862
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Code:
    var pogo="newo";
    window[pogo] = 'something';
    alert(newo);
    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="^$">

  3. #3
    SitePoint Addict
    Join Date
    May 2007
    Posts
    242
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    var olo=document.getElementsByTagName("h1")[0].firstChild.nodeValue;

    var solo=document.getElementsByTagName("h2")[0].firstChild.nodeValue;
    Thank you @felgall. Got it but couldnt assign olo value as a new variable name. The new variable value will also grab solo value. How can I solve it?


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
  •