Run code when the input box gets focus

Jamie's Avatar

Jamie

07 Nov, 2011 03:32 PM

I want to detect when the input box gets focus from the user. You'd hope something like

$("#myInputID").click(function(){…}); or
$("#myInputID").focus(function(){…});

would work, and it does, but the code also gets run when you click on an item in the results list. I don't want to know that.

The reason I want this is because I have a particular input box where the user is only allowed to have one item at a time. If they click back in the input box, I want to be able to clear it for them.

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac