Kosmo零
Kosmo零

Reputation: 4151

How to capture input's type = 'text' clear event?

<input type='text' onchange="reportAnswer(1, this.value);" 
onkeyup="this.onchange();" onpaste="this.onchange();" 
oncut="this.onchange();" 
onclear = "this.onchange();" />

enter image description here

How to capture that change? This is IE11.

P.S. I added onclear handler because run out of ideas what to do.

Upvotes: 6

Views: 25842

Answers (3)

Ilan
Ilan

Reputation: 11

so its been 8 years but had the same problem and this was the first answer to show up found the answer in to this question here: How do you detect the clearing of a "search" HTML5 input?

tl:dr

 $(some-input).on("search", function() { }); 

does the trick

Upvotes: 0

CHP
CHP

Reputation: 51

You can use the event of "oninput":

// Try to change value of the input below
<input id="input1" />

var input = document.getElementById("input1");
input.oninput = function(){alert("Value changed");}

Upvotes: 4

T.J. Crowder
T.J. Crowder

Reputation: 1074268

You haven't said what's providing that [x], which is probably relevant, but the one event you haven't tried yet is input so: Live Example

<input type='text'
    onchange="reportAnswer(1, this.value);"
    onkeyup="this.onchange();"
    onpaste="this.onchange();"
    oncut="this.onchange();"
    oninput="this.onchange();" />

(No idea if it works, IE11 doesn't add that box for me on Windows 8.1.)

More likely, though, you need to hook into something provided by whatever it is that's providing that [x].

Upvotes: 5

Related Questions