Web Analytics Made Easy -
StatCounter A var question - CodingForum

Announcement

Collapse
No announcement yet.

A var question

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • A var question

    I have two variables "var1" "var2"

    See example below:

    var var1 = 3;
    var var2 = 'var1';

    How do I make so var2 = var1 = 3 and not 'var1'?

  • #2
    Take the single quotes off around var1?

    Comment


    • #3
      This was an simple example just to show what I needed to accompish.
      The "real" thing isn't this simple...

      Comment


      • #4
        In another programming language, to accomplish what I am after is:

        exp(var2) , and this would then be 3, but this is javascript and I don't how this is done here.

        Comment


        • #5
          Are you trying to do this?

          var var2 = "\"" + var1 + "\"";
          hmm... ?

          Comment


          • #6
            if you write
            var2=var1 then var2 gets the value of var1

            Comment


            • #7
              Originally posted by Garadon
              if you write
              var2=var1 then var2 gets the value of var1
              Exactly what Nightfire said.

              Are you trying to do this?

              var var2 = "\"" + var1 + "\"";
              Not really.


              Seriously, don't you understand what I want??

              I have 2 variables, one by the name "var1" and one "var2".
              The one named "var1" contains a number, 3.
              And the one named "var2" contains a text, which is exactly the same as the other variable I want to use, namly "var1".

              If I now write alert(var2), the text "var1" is popped up, but I want the text that is in the variable called "var1" popping up.

              So instead of "var1" popping up, I want "3" to be popping up.

              So, is there a way to convert the text so it thinks that it's the variable called the same thing instead of the name of the variable itself?

              Comment


              • #8
                alert(window[var2])

                Comment


                • #9
                  Originally posted by Garadon
                  alert(window[var2])
                  Wtf, it works!

                  Where can I read about this?
                  MSDN?

                  Comment


                  • #10
                    Glenn
                    vBulletin Mods That Rock!

                    Comment

                    Working...
                    X