Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I trigger ESC button to clear text entered in text box?

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

I know it is something with

onkeydown="if (event.keyCode == 27)
like image 624
jprim Avatar asked Dec 01 '22 05:12

jprim


1 Answers

Declare a function which 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);" />
like image 64
Darin Dimitrov Avatar answered Dec 03 '22 23:12

Darin Dimitrov