Passing a var as an argument

Posted by Lienau on Stack Overflow See other posts from Stack Overflow or by Lienau
Published on 2010-04-09T23:26:45Z Indexed on 2010/04/09 23:33 UTC
Read the original article Hit count: 331

Filed under:
|

On a site I'm making I need to have a progress bar, I found one that suited my needs. By default it will incrementally change the color when a certain percentage is reached (0-30 red, 30-70 orange, etc). My only problem is changing them, I can set them easily with a static number such as 50, but when I try to do it dynamically (ie: 2000*.3 = 600) it fails. I don't know much js/jquery so this is especially difficult for me, if you could help that would be great. I'm pretty sure it's something really simple I'm missing.

The code that Fails:

var barmax = 2000;
var orangeBound = Math.round(barmax * .3);
var greenBound  = Math.round(barmax * .7);
//alert(orangeBound+":"+greenBound);
$("#pb1").progressBar({ max: barmax, textFormat: 'fraction',
barImage: {
       0: 'images/progressbg_red.gif',
       orangeBound: 'images/progressbg_orange.gif',
       greenBound: 'images/progressbg_green.gif'}
    });

The code that works but I can't use because it has to be dynamic:

$("#pb1").progressBar({ max: barmax, textFormat: 'fraction',
    barImage: {
       0: 'images/progressbg_red.gif',
       600: 'images/progressbg_orange.gif',
       1400: 'images/progressbg_green.gif'}
    });

If you need to see the source, here. Thanks again!

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about JavaScript