View Full Version : Adding up dynamically created variables

10-18-2006, 11:10 AM

If I have 2 or more javascript variables like this

var id_1234 = 23;
var id_5678 = 27;

var total = id_1234 + id_5678; \\Ans 50

How could I add them up if I don't know the part after id_ in the variable name??

(that is being created dynamically by the perl script depending on the ID numbers the user inputs)

10-18-2006, 03:19 PM
Can you make the perl script generate an id array instead of random variable names, like:

id[1234] = 13;
id[4513] = 27;

And then you can manipulate the array. Or, you can loop over every variable in the window object to find things that match the pattern of your variable names, but that sux.

10-18-2006, 08:39 PM
Thanks Beagle,
The "id array" would work brilliantly.
Thanks for the idea.