Andrew
Andrew

Reputation: 83

How To Update JQuery Progress Bar Value from a Variable

I have a Problem Regarding the JQuery Progress Bar.

I Need to set the Value of the Progress bar with the Value stored in a Javascript Variable.

 $(document).ready(function () 
{
    var text = $('.Gadget').find('input[name="Percentage"]').val();


 $(function() 
{
    $( ".ProgressBar" ).progressbar({
    value: 59
});

});

});

The Above code works fine, but as there is Value 59 the value is always Constant.

What I Really need is that instead of the 59, there will be the value of the text Variable.

Note: if I Put Value:text, the Progress bar disappears

Thank You, Andrew Borg

Upvotes: 1

Views: 3961

Answers (1)

Samich
Samich

Reputation: 30095

You need to do it in the single document.ready handler. Use parseInt() to make it numeric:

$(document).ready(function () {
    var text = $('.Gadget').find('input[name="Percentage"]').val();

    $( ".ProgressBar" ).progressbar({
       value: parseInt(text)
    });

});

Upvotes: 4

Related Questions