Search code examples
javascriptjqueryhtmluislider

Slider updates select value now to Get the select value to update the slider value?


I have a created a slide bar to determine the max number of bytes that a user wants to download. This slider is connected to a select box. As the slider moves along the line, it updates the value in the select box. However, when you chose a value from the select box it does not update the value of the slider. How do i get it to update both ways??

JavaScript

        $(function() {
            var select = $( "#camlogbytes");
            var slider = $( " <div id='slider'></div>").insertAfter(select).slider({
                min: 1,
                max: 6,
                step: 1,
                value: select[0].selectedIndex + 1, 
                slide: function(event, ui) {
                    select[0].selectedIndex = ui.value - 1;
                }
            });
            $("camlogbytes").change(function() {
                slider.slider("value", this.selectedIndex + 1);
            });
        });

HTML

    <tr>
        <td class="column1">Max number of bytes per Camera Log:</td>
        <td id="sliderbytes">
            <select name="camlogbytes" id="camlogbytes">
            <option value="0"selected="selected">0</option>
            <option value="1">1</option>
            <option value="2">2</option>
            <option value="3">3</option>
            <option value="4">4</option>
            <option value="5">5</option>
            </select>
        </td>
    </tr>

Solution

  • You will kick yourself, you missed the # at the start of the selector here:

     $("#camlogbytes").change(function() {
            slider.slider("value", this.selectedIndex + 1);
     });