I know...">

How to call the ESC button to delete the text entered in the text box?

   <input type="text" id="search" size="25" autocomplete="off"/>

I know this is something with

onkeydown="if (event.keyCode == 27)
+3
source share
3 answers

Declare a function that will be called when a key is pressed:

function onkeypressed(evt, input) {
    var code = evt.charCode || evt.keyCode;
    if (code == 27) {
        input.value = '';
    }
}

And the corresponding markup:

<input type="text" id="search" size="25" autocomplete="off" 
       onkeydown="onkeypressed(event, this);" />
+7
source
<input type="text" value="" onkeyup="if ( event.keyCode == 27 ) this.value=''" />

That should work.

+5
source
function keyPressed(evt) {
 if (evt.keyCode == 27) {
    //clear your textbox content here...
    document.getElementById("search").value = '';
 }
}

Then in the input tag ...

<input type="text" onkeypress="keyPressed(event)" id="search" ...>
+1
source

Source: https://habr.com/ru/post/1762592/


All Articles