You seem to be overcomplicating things slightly there... something like this is probably all you need (I have added loads of comments to the code to try explain what is going on):
var amountFields = [],
selector = '.slide',
opts = {
value: 4,
min: 1,
max: 7,
step: 1,
slide: function(e, ui) {
var i = ui.handle.closest(selector).data('sliderId');
amountFields[i].val(ui.value);
}
};
// because you have used a '.slide' class
// name on your sliders, you can use .each()
// to iterate through them instead of using
// your for loop that assumes there are only
// ever 5 sliders
$(selector).each(function() {
// get 'i' from the sliders id attribute
var i = this.id.replace(/[a-z\-_]/gi, '');
// initialise slider on the element
// and store 'i' within the elements
// data for easy access in the
// slide method later
$(this).slider(opts).data('sliderId', i);
// DOM querying is a hit on performance
// so cache the jQuery object for re-use
// in the slide method instead of
// re-querying the DOM
amountFields[i] = amountFields[i] || $('#amount' + i);
// set the amounts initial value using
// the opts object instead
amountFields[i].val(opts.value);
});
Haven't tested this so not 100% there are no errors in the above but something like that should work.
=================================== UPDATE ======================================
Since you thought the above looked more complicated, here is the exact same code without the comments and caching to show you just how simple it actually is:
var opts = {
value: 4,
min: 1,
max: 7,
step: 1,
slide: function(e, ui) {
var i = ui.handle.closest('.slide').data('sliderId');
$('#amount' + i).val(ui.value);
}
};
$('.slide').each(function() {
var i = this.id.replace(/[a-z\-_]/gi, '');
$(this).slider(opts).data('sliderId', i);
$('#amount' + i).val(opts.value);
});
I added in the caching before for performance so without it, it will perform slower but will still work. The .replace() bit is getting the slider ID and removing any letters, hyphens or underscores to leave just the number, the bit we need.
:Palertinto the slider function - is it actually being called?