Jquery UI Slider change value of slider when changed in input field
Asked Answered
F

3

17

$("#storlekslider").slider({
  range: "max",
  min: 0,
  max: 1500,
  value: 0,
  slide: function(event, ui) {
    $("#storlek_testet").val(ui.value);
    $(ui.value).val($('#storlek_testet').val());
  }
});
// $( "#storlek_testet" ).val( $( "#storlekslider" ).slider( "value" ) );

$("#storlek_testet").change(function() {
  $("#storlekslider").slider("value", $(this).val());
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.9.0/jquery-ui.js"></script>
<link rel="stylesheet" type="text/css" href="https://code.jquery.com/ui/1.9.0/themes/base/jquery-ui.css">
<div id="storlekslider"></div>
<input type="text" name="storlek" id="storlek_testet" value="500" />

Heres a js fiddle

im trying to get the slider to jump to the correct position when I change the value in the input field. Iam using the Jquery UI slider.

Furlani answered 9/10, 2012 at 7:53 Comment(0)
M
20

You attach to the change event of your input like so:

$("#storlek_testet").change(function() {
    $("#storlekslider").slider("value", $(this).val());
});
Modie answered 9/10, 2012 at 8:7 Comment(2)
$(this).val() can be used instead of the selector $("storlek_testet").val()Irishirishism
there is also # and ); missing ;-)Kiki
P
10

Change values from several inputs:

$("#input-1").change(function() {
    $("#slider").slider('values',0,$(this).val());
});
$("#input-2").change(function() {
    $("#slider").slider('values',1,$(this).val());
});

https://jsfiddle.net/brhuman/uvx6pdc1/

Phalarope answered 3/7, 2016 at 13:22 Comment(0)
K
5
$("#storlek_testet").keyup(function() {
    $("#storlekslider").slider("value" , $(this).val())
});

http://jsfiddle.net/C8X4D/

Kiki answered 9/10, 2012 at 8:14 Comment(2)
how to implement it for wordpress plugin option panelVentriloquist
change() is preferable to keyup() if input is of type number, because keyup() won't apply changes when the field up/down buttons are used to change the input value.Ess

© 2022 - 2024 — McMap. All rights reserved.