Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 243
Kosmo零 Avatar asked Sep 30 '22 21:09

Kosmo零


2 Answers

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].

like image 100
T.J. Crowder Avatar answered Oct 13 '22 00:10

T.J. Crowder


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");}
like image 25
CHP Avatar answered Oct 12 '22 23:10

CHP