Results 1 to 4 of 4

Thread: javascript dynamic variable name

  1. #1
    Join Date
    Mar 2009
    Posts
    33

    javascript dynamic variable name

    I am matching in the new text of JavaScript, but one ran into with a problem and I cannot find out how to solve it. Basically, which I want is to be able to partly use a variable of the name of a new object.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: javascript dynamic variable name

    I think you wanted to do something like this :

    Code:
    for (i = 0; i < selectedTypes[trendCategory].length; i++)
      var selectId = 'dynamicSelect' + i;
      document.getElementById(selectId) = new Option(selectedTypes[trendCategory][i],selectedTypes[trendCategory][i],false);

  3. #3
    Join Date
    Apr 2008
    Posts
    2,005

    Re: javascript dynamic variable name

    There are some ways to do what you want. For example:


    Code:
    JavaScript Code:
    var myArray = {   value1: "hello",   value2: "what's up",   value3: "not much"} 
    for (var i in myArray) { 
       alert(test[i]); 
    }

  4. #4
    Join Date
    May 2008
    Posts
    2,297

    Re: javascript dynamic variable name

    TRY THIS :

    Code:
    eval("eval('object'+id+' = new GLatLng(x,y)');");
    
    and three evals too:
    eval("eval(\"eval('object'+id+' = new GLatLng(x,y)');\")");
    
    
    but you don need eval in your case.
    you need check the variable
    if(object1)
    {
       //do something with it
    }

Similar Threads

  1. How to Pass a Javascript variable to a PHP script
    By leshaspar in forum Software Development
    Replies: 4
    Last Post: 24-11-2010, 10:48 AM
  2. How to setup a JavaScript Object Notation variable?
    By hatred in forum Software Development
    Replies: 4
    Last Post: 04-02-2010, 02:25 AM
  3. Replies: 5
    Last Post: 25-01-2010, 04:59 PM
  4. Passing Javascript variable value into JSP scriptlet
    By ComPaCt in forum Software Development
    Replies: 3
    Last Post: 23-09-2009, 03:32 PM
  5. Replies: 2
    Last Post: 28-08-2009, 07:51 PM

Tags for this Thread

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
  •  
Page generated in 1,710,823,735.68060 seconds with 17 queries