Create a variable which is named depending on an ID number?

Posted by gray on Stack Overflow See other posts from Stack Overflow or by gray
Published on 2012-11-24T16:44:38Z Indexed on 2012/11/24 17:04 UTC
Read the original article Hit count: 208

Filed under:
|

Is there any way to create a variable, and add an ID to the end of the actual variable name?

I have a variable called 'gauge', used to create a new Gauge object:

var gauge = new Gauge(target).setOptions(opts);

I want to add an ID to the variable, so something like:

var gauge+id = new Gauge(target).setOptions(opts);

It's because I'm creating a number of these objects, and have a specific ID already for each one, which I want to attach to the gauge object if possible?

All my code for this function is below, if it gives you a better idea of what i need to do:

    function go(id, votes)
{

var val = $('#votes_'+id).text();

var target = document.getElementById('foo_'+id); // your canvas element

var gauge = new Gauge(target).setOptions(opts); // create sexy gauge!
gauge.maxValue = 100; // set max gauge value
gauge.animationSpeed = 20; // set animation speed (32 is default value)
var a=votes+0.5;
gauge.set(val); // set actual value
}

My main problem arises on the last line. It says gauge.set(val), and it only sets the last object, ignoring all the other ones...

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about variables