Capture data from jQuery Mobile GUI / form elements like sliders, or the flip switch/toggle, and store in a var?

Posted by Carl Foggin on Stack Overflow See other posts from Stack Overflow or by Carl Foggin
Published on 2012-10-11T03:33:15Z Indexed on 2012/10/11 3:37 UTC
Read the original article Hit count: 148

Filed under:
|
|

I have this code, which executes without error, it shows "** slider change **" in the debug console every time the slider changes. But I cannot figure out how to capture the value of the slider so I can store it in a var. Can you help, I'm hoping it's a simple thing.

$( '#page4_Options' ).live( 'pageinit', function(event){

    var slideTime = userOptions.getSlideTime() / 1000; // userOptions is my Object to get/set params from localStorage.

    $("input[id='slider']").val(slideTime).slider("refresh"); // set default slide time when page init's.

    console.log("userOptions.getSlideTime()", userOptions.getSlideTime() ); 

    $( "#slider" ).bind( "slidestop", function(event, ui) { 
        console.log("** slider change **");
        // How do I capture the new slider value into a var?
     });
});

Here's the HTML with the slider, it's in a tag:

   <div data-role="fieldcontain">
      <label for="slider">Slide Duration (seconds):</label>
      <input type="range" name="slider" id="slider" value="2" min="0" max="60" />
   </div>

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about gui