Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Event fired when clearing text input on IE10 with clear icon

On chrome, the "search" event is fired on search inputs when user clicks the clear button.

Is there a way to capture the same event in javascript on Internet Explorer 10?

enter image description here

like image 283
ghusse Avatar asked Jan 24 '13 09:01

ghusse


2 Answers

The only solution I finally found:

// There are 2 events fired on input element when clicking on the clear button: // mousedown and mouseup. $("input").bind("mouseup", function(e){   var $input = $(this),       oldValue = $input.val();    if (oldValue == "") return;    // When this event is fired after clicking on the clear button   // the value is not cleared yet. We have to wait for it.   setTimeout(function(){     var newValue = $input.val();      if (newValue == ""){       // Gotcha       $input.trigger("cleared");     }   }, 1); }); 
like image 158
ghusse Avatar answered Oct 05 '22 03:10

ghusse


The oninput event fires with this.value set to an empty string. This solved the problem for me, since I want to execute the same action whether they clear the search box with the X or by backspacing. This works in IE 10 only.

like image 32
Lucent Avatar answered Oct 05 '22 03:10

Lucent