Jump to content

JS - How to stop Tab key from blur the input box?


Recommended Posts

Hello guys,

I have a frustrating problem. I want to stop the caret from changing input focus (jump outside) when I press tab. Instead remain in the input field.

Basically I want to create an auto-complete word when I press tab.

What I've tried something similar to this:


<input type="text" onKeyUp="preventTab(e)" onKeyPress="preventTab(e)" onKeyDown="preventTab(e)">
function preventTab(e){
   return false;


All keys trigger this function except tab key.

- Please delete the thread. The code worked on KeyDown, no idea why it didn't worked before.

Edited by HazardBoy
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...