Reputation: 145
I am using the jQuery UI range slider and I have two hidden inputs to store the minimum and maximum values of the slider so as to later use them for a PHP query. But what happens is that my min and max value variables don't store the actual values but the ones before them. So there will be a +-1 variation respect to the real value. I guess I have to find a way to update the values before submitting the form. The code I am using is
<script>
$(function() {
$("#slider-range").slider({
range: true,
min: 1,
max: 10,
values: [ 1, 10 ],
slide: function( event, ui ) {
$("#minvalue").val($("#slider-range").slider("values", 0));
$("#maxvalue").val( $("#slider-range").slider("values", 1));
$("#amount").val(ui.values[ 0 ] + " - " + ui.values[ 1 ]);
}
});
$("#amount").val( $("#slider-range").slider("values", 0) +
" - " + $("#slider-range").slider("values", 1));
});
</script>
<input type="hidden" id="minvalue" name="minvalue" />
<input type="hidden" id="maxvalue" name="maxvalue" />
Upvotes: 0
Views: 2796
Reputation: 15616
here try this:
$(function() {
$("#slider-range").slider({
range: true,
min: 1,
max: 10,
values: [0, 11],
slide: function(event, ui) {
$("#minvalue").val(ui.values[0]);
$("#maxvalue").val(ui.values[1]);
$("#amount").val(ui.values[0] + " - " + ui.values[1]);
}
});
$("#amount").val($("#slider-range").slider("values", 0) + " - " + $("#slider-range").slider("values", 1));
});
Upvotes: 1