2

I need to link an undefined number of input type="hidden" to some progress bar of JQuery UI (http://jqueryui.com/demos/progressbar/). I never have the same number of hidden and progress bar for each user i use. (If i have 5 user, i will have 5 progress bar and 5 hidden)

I would like to know how could i, dynamically, detect the number of input type="hidden" and progress bar and link them.

Thanks

Andrew Whitaker
  • 124,656
  • 32
  • 289
  • 307
Charles Lemarier
  • 181
  • 1
  • 1
  • 9

2 Answers2

2

Is this what you want?

$('input:hidden').each(function(i, input) {
    $('.progressBar').eq(i).progressbar({
        value: Number($(input).val())
    });
});

Example: http://jsfiddle.net/william/LZCqA/

William Niu
  • 15,798
  • 7
  • 53
  • 93
0

I'm not real sure if this is what you're looking for...

If you're wanting to select all of the inputs of type hidden, the best way to do it would likely to be either set a class on all of the inputs you're interested in or, if you will always be interested in every hidden input on the page, you can just select them all.

Here are examples of how to do each:

$('.my-input-class').each(function(){//do whatever here...});

$('input[type="hidden"]').each(//same thing here...);

Using ".each" in this case is just an example of working with every input. Just doing $('selector') will, obviously, select all of the elements.

Does that help?

Small Update:

After re-reading your question, this may help too... Inside your .each(), you could then poll your jQuery progress bar and set the hidden input to the value of the progress bar. However, I'll admit, I can't really think of a situation where you would want/need to do that.

Anthony
  • 734
  • 3
  • 9
  • 22
  • Well i want to show more then one progress bar on the same page. I want to link the value of the progress bar to an input type hidden so the hidden's value is the same as the progress bar for each. (if i got 3 progress bar i want the progress bar1 to have an input1 with the same value) – Charles Lemarier Aug 16 '11 at 19:25
  • Ah, I see now. I would recommend making your own way to identify each progress bar/hidden input combination. For example, when you print them out on the page, give the first progress bar an id of 'progress-bar-1' and give the hidden input an id of 'hidden-input-1' (obviously, name them whatever you want, just give them a unique number). Doing this, you will be able to get at the specific progress bars and inputs that you're trying to keep in synch. To help you further, you'll need to tell us how you know you need to update the value of a progress bar/input pair. – Anthony Aug 17 '11 at 13:20