I'm using the JQuery slider for a width range. Here's my HTML:
<div id="divWidth">
Width:
<div>
<input type="text" class="sliderValue" data-index="0" value="10" id="txtWidthFt0"
runat="server" style="width: 20px" />'
<input type="text" class="sliderValue" data-index="0" value="10" id="txtWidthIn0"
runat="server" style="width: 20px" />" to
<input type="text" class="sliderValue" data-index="1" value="10" id="txtWidthFt1"
runat="server" style="width: 20px" />'
<input type="text" class="sliderValue" data-index="1" value="10" id="txtWidthIn1"
runat="server" style="width: 20px" />"
</div>
<br />
<div id="sliderWidth">
</div>
</div>
I was able to get the textbox values to change as the slider moves. I need help doing it the other way around - changing the slider values as the textbox values change.
Here's my current javascript, which I tweaked from this post:
<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.8.3.js"></script>
<script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css" />
<script type="text/javascript">
function getFeet(n) {
return Math.floor(n / 12);
}
function getInches(n) {
return (n % 12);
}
$(document).ready(function () {
$("#sliderWidth").slider({
min: 1,
max: 500,
range: true,
values: [1, 500],
slide: function (event, ui) {
for (var i = 0; i < ui.values.length; ++i) {
$("#txtWidthFt" + i).val(getFeet(ui.values[i]));
$("#txtWidthIn" + i).val(getInches(ui.values[i]));
}
}
});
// need help here:
$("#divWidth input").change(function () {
var $this = $(this);
$("#sliderWidth").slider("values", ?);
});
});
</script>
I know I can add a change event for each textbox and do it that way. I'm looking for a way to do it without having an event for each textbox / with less code. Any help is appreciated.