0

Clearing the textarea on escape?

https://code.sololearn.com/WhH3Q09RHeQj/#js So I need this textarea to be cleared when escape is pressed, but only if the textarea is focused/active. Otherwise, It should alert the user that he/she must focus the textarea before they can clear it. Can somebody help me? I know how to clear it with escape, the problem is I need it to clear ONLY if the textarea is focused/active.

31st Aug 2018, 1:47 AM
Daniel Cooper
Daniel Cooper - avatar
5 odpowiedzi
+ 3
Try it. It works
31st Aug 2018, 7:43 AM
Calviղ
Calviղ - avatar
+ 1
change to document.getElementById("TextArea" ).addEventListener( "keydown", Clear );
31st Aug 2018, 2:49 AM
Calviղ
Calviղ - avatar
0
That's what it was initially Calviղ I changed it to body while experimenting and I guess I saved it by accident either way, it doesn't do exactly what I wanted it to I tried hasFocus but I couldn't get it to work :(
31st Aug 2018, 4:14 AM
Daniel Cooper
Daniel Cooper - avatar
0
Calviղ Check it out. I got it to do what I wanted. https://code.sololearn.com/WhH3Q09RHeQj/?ref=app
1st Sep 2018, 6:56 AM
Daniel Cooper
Daniel Cooper - avatar
0
Calviղ Check it out. I got it to do what I wanted. https://code.sololearn.com/WhH3Q09RHeQj/?ref=app
1st Sep 2018, 6:56 AM
Daniel Cooper
Daniel Cooper - avatar