1
  1. What is the use of Dynamic variables? Any scenarios?
  2. Can I attach this value to a TextField?

    var data = "testVariable";
    eval("var temp_" + data + "=123;");
    alert(temp_testVariable);
    
Ates Goral
  • 137,716
  • 26
  • 137
  • 190
John Cooper
  • 7,343
  • 31
  • 80
  • 100

2 Answers2

6

What is the use of Dyanmic variables? Any Scenarious

For when people haven't heard of objects or arrays.

Can i attach this value to a TextField?

Yes.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
6

The answer to 2) is 'yes you can'.

However for 1), and overall, you probably shouldn't be using eval: Why is using the JavaScript eval function a bad idea?

As another comment and the currently upvoted answer says - either use arrays or a map.

Community
  • 1
  • 1
Andras Zoltan
  • 41,961
  • 13
  • 104
  • 160