I'm using a jQuery slider as a price range selector in a form.
I'd like to have the form submit automatically when one of the values has been changed. I used a couple of examples I found on SO but they didn't work with my code.
<form action="itemlist.php" method="post" enctype="application/x-www-form-urlencoded" name="priceform" id="priceform" target="_self">
<div id="slider-holder">
Prices: From <span id="pricefromlabel">100 €</span>
To <span id="pricetolabel">500 €</span>
<input type="hidden" id="pricefrom" name="pricefrom" value="100" />
<input type="hidden" id="priceto" name="priceto" value="500" />
<div id="slider-range"></div>
<input name="Search" type="submit" value="Search" />
</div>
</form>
This is the code that displays the values of the slider and updates 2 hidden form fields I use to store the prices in order to submit:
<script>
$(function() {
$("#slider-range" ).slider({
range: true,
min: 0,
max: 1000,
values: [ <?=$minprice?>, <?=$maxprice?> ],
start: function (event, ui) {
event.stopPropagation();
},
slide: function( event, ui ) {
$( "#pricefrom" ).val(ui.values[0]);
$( "#priceto" ).val(ui.values[1]);
$( "#pricefromlabel" ).html(ui.values[0] + ' €');
$( "#pricetolabel" ).html(ui.values[1] + ' €');
}
});
return false;
});
</script>
I've tried adding this code as well as an data-autosubmit="true" attribute to the div but no result.
$(function() {
$('[data-autosubmit="true"]').change(function() {
parentForm = $(this).('#priceform');
clearTimeout(submitTimeout);
submitTimeout = setTimeout(function() { parentForm.submit() }, 100);
});
I've also tried adding a $.post() event to the slider but I'm not very good with jQuery so I'm probably doing it wrong. Any help will be appreciated.