Op_Je_Plaatsman
Op_Je_Plaatsman

Reputation: 37

getting the value from a jquery slider

I'm working on this slider.. that I want to use to change the margin of a ..but my problem is getting the value out of it. even if I trie to show the value with an alert like this:

window.alert($( "#slider" ).val()); 

nothing shows up. Anyone an idea to what i;m doing wrong??

ThanX!!!

<!DOCTYPE html>
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link href="./demo_files/jquery-ui.css" rel="stylesheet" type="text/css">
<link href="./styles.css" rel="stylesheet" type="text/css">
<script src="./demo_files/jquery.min.js"></script>
<script src="./demo_files/jquery-ui.min.js"></script>
<style>     
    #demo-frame > div.demo { padding: 10px !important; };
</style>


<script>
    function displayVals() {

        $( "#slider" ).slider();

        var step = $( "#slider" ).slider( "option", "step" );

        $( "#slider" ).slider( "option", "step", 20 );  


        var singleValues = $("#slider").val();  
        $("p").html("<b>Single:</b> " + singleValues); 

        $("#slider").change(displayVals);                       
};

</script>
</head>

<div class="demo">

<div id="slider"></div>

</div><!-- End demo -->

<p></p>

<script> displayVals();</script>
</body></html>

Upvotes: 0

Views: 807

Answers (1)

Alnitak
Alnitak

Reputation: 339786

You need:

var singleValues = $('#slider').slider('value');

(or 'values' if it's a multi-handled or range slider)

http://jqueryui.com/demos/slider/#method-value

Upvotes: 1

Related Questions