Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 17-06-2009
Member
 
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.
Reply With Quote
  #2  
Old 17-06-2009
Member
 
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);
Reply With Quote
  #3  
Old 17-06-2009
Member
 
Join Date: Apr 2008
Posts: 2,001
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]); 
}
Reply With Quote
  #4  
Old 17-06-2009
Member
 
Join Date: May 2008
Posts: 2,293
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
}
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "javascript dynamic variable name"
Thread Thread Starter Forum Replies Last Post
How to Pass a Javascript variable to a PHP script leshaspar Software Development 4 24-11-2010 10:48 AM
How to setup a JavaScript Object Notation variable? hatred Software Development 4 04-02-2010 02:25 AM
How to change a variable that is saved in an object structure in JavaScript? DANIEL 602 Software Development 5 25-01-2010 04:59 PM
Passing Javascript variable value into JSP scriptlet ComPaCt Software Development 3 23-09-2009 03:32 PM
Runtime Error 91 : Object Variable or with block variable not set Ryan21 Software Development 2 28-08-2009 07:51 PM


All times are GMT +5.5. The time now is 01:13 AM.