Nevi
Nevi

Reputation: 328

jQuery Spinner Change Event

i need to to do something on spinner change value event but apparently i need to click outside the spinner box to get the value, i wanted to get the value instantly on spin increment click.

JS Fiddle

    $(function() {
      $("#spinner").spinner({
        change: function(event, ui) {
          console.log(this.value)
          if (this.value == '1') {
            alert(this.value)
          }
        }
      });
    } 
);

http://jsfiddle.net/m8gdhyy5/

Upvotes: 2

Views: 2903

Answers (2)

Arun P Johny
Arun P Johny

Reputation: 388316

You need to use the spin event

$(function() {
  $("#spinner").spinner({
    spin: function(event, ui) {
      snippet.log('value: ' + ui.value)
      if (ui.value == '1') {
        snippet.log('matched: ' + ui.value)
      }
    }
  });
});
<!-- To show result in the dom instead of console, only to be used in the snippet not in production -->
<!-- Provides the `snippet` object, see http://meta.stackexchange.com/a/242144/134069 -->
<script src="http://tjcrowder.github.io/simple-snippets-console/snippet.js"></script>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<link href="http://code.jquery.com/ui/1.11.4/themes/ui-lightness/jquery-ui.css" rel="stylesheet" />
<input id="spinner" />

;

Upvotes: 2

Eric Guan
Eric Guan

Reputation: 15990

Try this

http://jsfiddle.net/m8gdhyy5/2/

$(function() {
  $("#spinner").spinner();
  $("#spinner").on("spinstop", function(){
     alert($(this).spinner('value'));
  });
});

Upvotes: 0

Related Questions