Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect when a text input changes with ie8

I want to detect when a text input changes. I tried these, which worked in firefox but not in ie 8.

$('#taskSearch').bind('input', function() {
     alert($(this).val());
});
$('#taskSearch').live('input', function() {
    alert($(this).val());
});
$('#taskSearch').change(function() {
    alert($(this).val());
});
like image 938
Luke Avatar asked Aug 03 '12 08:08

Luke


3 Answers

You can use onpropertychange for IE6+:

$("#taskSearch").on("propertychange", function(){
alert($(this).val());
});
like image 127
Mori Avatar answered Oct 23 '22 22:10

Mori


The following solution works for me in IE8 and modern browsers for both changes by keys, scroll or the arrow buttons within the a type="num" input field:

$('#element').on('keyup change', function() {
  // do something
});
like image 3
Mark de Vries Avatar answered Oct 23 '22 22:10

Mark de Vries


The last one (and only the last one) is correct, but you were missing a closing parenthesis:

$('#taskSearch').change(function() {
    alert($(this).val());
});

.live() is deprecated (and the syntax is incorrect), and the syntax for .bind() is also incorrect; the name of the event is 'change', not 'input'. See the documentation for .change().

like image 2
nbrooks Avatar answered Oct 23 '22 23:10

nbrooks