I have a jQuery UI range slider set up. When the slider controls are moved my code inserts the lower range value into a hidden input, and also the higher range value into a hidden input. These values constantly change as the slider is moving, but there is a problem. If the lower value stops on £60,000 for example, the value inserted into the hidden div will be £40,000. It is always 1 position out of sync. This is my first problem I need to fix. The values are set as #minPrice and #maxPrice in my code.
The second problem occurs on form submission. I need to get the values of the hidden inputs and (on the page load after the form submission) pass them back the to the text input that shows the range for the sliders e.g. 40,000 to 60,000. This input has the ID of #amount in the code.
Here is my code:
// Set increments for sale slider prices
var increments = ['0', '20,000', '40,000', '60,000', '80,000', '100,000', '120,000', '140,000', '160,000', '180,000', '200,000', '220,000', '240,000', '260,000', '280,000', '300,000', '320,000', '340,000', '360,000', '380,000', '400,000', '420,000', '440,000', '460,000', '480,000', '500,000', '520,000', '540,000', '560,000', '580,000', '600,000', '620,000', '640,000', '660,000', '680,000', '700,000', '720,000', '740,000', '760,000', '780,000', '800,000', '820,000', '840,000', '860,000', '880,000', '900,000', '920,000', '940,000', '960,000', '980,000', '1,000,000', '1,100,000', '1,200,000', '1,300,000', '1,400,000', '1,500,000', '1,600,000', '1,700,000', '1,800,000', '2,000,000']
$('#sliderPriceSale').slider({
range: true,
min: 0,
step: 1,
max: 59,
values: [4, 15],
slide: function (event, ui) {
$('#amount').val(increments[ui.values[0]] + " to " + increments[ui.values[1]]);
var minPrice = $("#sliderPriceSale").slider("values", 0);
$('#minPrice').val(increments[minPrice]);
var maxPrice = $("#sliderPriceSale").slider("values", 1);
$('#maxPrice').val(increments[maxPrice]);
}
});
$('#amount').val(increments[$('#sliderPriceSale').slider("values", 0)] + " to " + increments[$('#sliderPriceSale').slider("values", 1)]);
Any help will be much appreciated.