John Kim
John Kim

Reputation: 1872

jQuery Mobile Dual Range slider

I made a dual range slider in JQM by placing slider on top of each other. Is there a way we can stop min exceeding max value?

I'm not sure slider is using HTML5 range input type

<style type="text/css">
            .priceRangeInfo{
                position: relative;
                height: 30px;
                margin-top: 60px;
            }
            .priceRangeInfo label{
                position: absolute;
                top: -30px;
                left: 10px;
            }                            /* moves label field */
            .priceRangeInfo #buying_slider_min{
                top: -40px;
                position: absolute;
                left: 100px;
            }       /* moves first input field */ 
            .priceRangeInfo #buying_slider_max{
                top: -40px;
                position: absolute;
                left: 170px;
            }      /* move second input field */ 
            .priceRangeInfo div.ui-slider{
                position: absolute;
            }                   /* move both sliders - adressing 1st slider with CSS is hard */ 
            .priceRangeInfo div:last-child{
                position: absolute;
                left: 0px;
            }                 /* correct 2nd slider position to fit exactly on top of 1st slider */
        </style>
        <div class="priceRangeInfo">
              <label for="buying_slider_min">Price</label>
              <input type="range" name="buying_slider_min" id="buying_slider_min" class="minBuyingSlider" value="0" min="0" max="100" />
              <input type="range" name="buying_slider_max" id="buying_slider_max" class="maxBuyingSlider" value="100" min="0" max="100" />
        </div>

Just found YUI has a great dual slider that works perfectly with JQM!!!

http://developer.yahoo.com/yui/examples/slider/slider_dual_with_highlight.html

Upvotes: 3

Views: 6098

Answers (2)

Moraru Viorel
Moraru Viorel

Reputation: 342

you must create the slider so: html:

 <div id="slider-container-zucker" class="slider_style"></div>

and js:

 $(function () {

$('#slider-container-zucker').slider({
    range: true,
    min: 0,
    max: 9,
    values: 0, 9,
    change: function (event, ui) {
        $.ajax({
            type: "GET",
            url: url,
            success: function (result) {
                $("#Result").html(result);
            }
        });            

    }
});

});

if something is not clear you can ask me

Upvotes: 0

Phill Pafford
Phill Pafford

Reputation: 85308

Would something like this work:

JS

$('#buying_slider_min').change(function() {
    var min = $(this).val();
    var max = $('#buying_slider_max').val();

    if(min > max) {
        $('#buying_slider_max').val(min);
      $('.maxBuyingSlider').slider('refresh');  
    }
});

HTML

<div class="priceRangeInfo">
      <label for="buying_slider_min">Price</label>
      <input type="range" name="buying_slider_min" id="buying_slider_min" class="minBuyingSlider" value="0" min="0" max="100" />
      <input type="range" name="buying_slider_max" id="buying_slider_max" class="maxBuyingSlider" value="100" min="0" max="100" data-track-theme="b"/>
</div>

CSS

.priceRangeInfo{
    position: relative;
    height: 30px;
    margin-top: 60px;
}
.priceRangeInfo label{
    position: absolute;
    top: -30px;
    left: 10px;
}                            /* moves label field */
.priceRangeInfo #buying_slider_min{
    top: -40px;
    position: absolute;
    left: 100px;
}       /* moves first input field */ 
.priceRangeInfo #buying_slider_max{
    top: -40px;
    position: absolute;
    left: 170px;
}      /* move second input field */ 
.priceRangeInfo div.ui-slider{
    position: absolute;
}                   /* move both sliders - adressing 1st slider with CSS is hard */ 
.priceRangeInfo div:last-child{
    position: absolute;
    left: 0px;
}

Upvotes: 3

Related Questions