...

View Full Version : Adding up dynamically created variables



rockdoc
10-18-2006, 12:10 PM
Hello,

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)

Beagle
10-18-2006, 04: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.

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum