Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6616311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:34:04+00:00 2026-05-25T20:34:04+00:00

I use jquery mobile sliders: <div data-role=fieldcontain> <input type=range name=slider1 id=slider1 value=0 min=0 max=255

  • 0

I use jquery mobile sliders:

  <div data-role="fieldcontain">
    <input type="range" name="slider1" id="slider1" value="0" min="0" max="255"  />
  </div><br><br>
  <div data-role="fieldcontain">
    <select name="switcher1" id="switcher1" data-role="slider">
      <option value="0">Off</option>
      <option value="255">On</option>
    </select> 
  </div>      

It should work in the following way:

  1. if switcher1 is touched, then slider1 value should be set either to 0 or to 255;
  2. if slider1 value is changed, then (a) if it is = 0, then switcher1 should be set to 0, (b) else switcher1 value should be set to 255.

I’ve tried to do so with change event (the same is used for switcher1 change()):

var slider1_val = "0";
$('#slider1').change(function () {
    sVal = $(this).val();
    if (slider1_val !== sVal) {
        $("#slider1").val(sVal).slider("refresh");
        if (sVal == 0) {
            $("#switcher1").val(0).slider("refresh");
        } else {
            $("#switcher1").val(255).slider("refresh");
        }
        slider1_val = sVal;
    }
});

But looks like each call of refresh calls change event, so I am getting infinite loop.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T20:34:05+00:00Added an answer on May 25, 2026 at 8:34 pm

    It should work in the following way:

    1. if switcher1 is touched, then slider1 value should be set either to 0 or to 255;
    2. if slider1 value is changed, then (a) if it is = 0, then switcher1 should be set to 0, (b) else switcher1 value should be set to 255.

    I’ve tried to do so with change event (the same is used for switcher1 change()):

    The fact that you have two very different criteria for changing each control should tip you off that the change event handlers should be different as well. Using the same handlers leads to the infinite loop you are experiencing. The code below accounts for the strict change criteria you’ve provided. Note that the slider1 change handler changes switcher1 only if it needs to be changed (based on your criteria), not every time it is called. Also, note that in the slider1 change handler, switcher1_val is set before calling refresh, so that in case .slider('refresh') does call the change handler, the change handler will not do anything, because switcher1_val is already updated.

    var linkSliders = function(sliderId, switcherId){
        var slider = $('#'+sliderId),
            switcher = $('#'+switcherId);
        var min = Math.min(switcher[0].options[0].value, switcher[0].options[1].value),
            max = Math.max(switcher[0].options[0].value, switcher[0].options[1].value);
        var sliderVal = switcherVal = min;
    
        // set the slider min/max to be the same as the switcher's, just in case they're different
        slider.attr('max', max).attr('min', min).slider('refresh');  
        slider.change(function(){
            var sVal = $(this).val();
            if(sliderVal != sVal){
                if( sVal == min && switcherVal!=min){
                    switcherVal=min;
                    switcher.val(min).slider('refresh');
                }else if(sVal>min && switcherVal!=max){
                    switcherVal=max;
                    switcher.val(max).slider('refresh');
                }
                sliderVal = sVal;
            }
        });  
    
        switcher.change(function(){
            var sVal = $(this).val();
            if(switcherVal != sVal){
                slider.val(sVal).slider('refresh');
                switcherVal = sVal;
            }
        });
    };
    
    linkSliders('slider1','switcher1');
    

    See the live example.

    Hope this helps.


    Update: As requested, the example has been modified to make it more general.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using phoneGap and jQuery Mobile . When I use a <div></div> tag
I want use JQuery mobile for the front-end of my mobile application, but I
I'm looking for a complete, step-by-step example of how to use jQuery Mobile 's
i want to use a icon in jQuery Mobile on a span element...and i
I'm using jquery mobile in my express project. How could I use Ajax for
Mobile browsers. Jquery dialog alert box. I don't want to use alert() because it
I'm trying to use Jquery Mobile for a web-app, and depending on what button
I use jQuery, jQuery UI and jQuery mobile to build a web application for
I'm working on a web app, which I decided to use jQuery Mobile for
I'm using PhoneGap and JQuery Mobile. I'm trying to use custom button icons. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.