3

I am using the html5 input type="number". I want to monitor this input for change, but:

  • because in browsers that support it It gets spin controls I can't just monitor .keyup,
  • because I don't want to wait for it to lose focus I can't just monitor .change.

How can I monitor it so I catch all cases where it's value is changed?

Brad Mace
  • 27,194
  • 17
  • 102
  • 148
Hailwood
  • 89,623
  • 107
  • 270
  • 423
  • possible duplicate of [HTML5 event listener for number input scroll - Chrome only](http://stackoverflow.com/questions/5669207/html5-event-listener-for-number-input-scroll-chrome-only) – Lightness Races in Orbit May 06 '11 at 00:54

2 Answers2

1

After looking at some of the question's on this site and using the mousewheel plugin I have got

$('#spinbox').bind('click change keyup mousewheel', function() {
  //10 ms timeout is for mousewheel otherwise you get the previous value
  var box = this;
  setTimeout(function() {console.log($(box).val());}, 10);
});

So you need to monitor it for

  • Click: clicking on the controls
  • change: fallback
  • keyup: for entering a value
  • mousewheel: hmmm... I wonder?
Hailwood
  • 89,623
  • 107
  • 270
  • 423
0

See: HTML5 number spinbox controls not triggering a change event?

You might use both oninput and onkeydown for compatibility.

Community
  • 1
  • 1
Ry-
  • 218,210
  • 55
  • 464
  • 476