2

I have an AJAX search script I'm making and it gives results in real time - problem is, I can't get my search function to trigger if the input is entered via right-click-paste method.

I've tried onchange and I've tried the jquery change events - nada. Then I tried the onmouseup event but it turns out it fires outside the input element because the right-click menu extends beyond its borders if that makes sense.

I've decided I can probably accomplish this with an entire document click handler that checks for the input text element's value length being greater than 0 when it triggers, but that seems sloppy and overkill.

Does anyone has a better suggestion?

1 Answer 1

4

Try paste event.

$('input[type="text"]').bind('paste', function() { ... });
Sign up to request clarification or add additional context in comments.

4 Comments

Wasn't aware this existed, will try asap.
You didn't close your $ parenthesis - if anyone else needs this later, be sure to add it.
Well, it seems to work if there is already text in the input box, for example if there is a name and I highlight it and right-click-paste a name in, it triggers - however, if I right-click-paste first thing before doing anything else on the page, it doesn't fire...I'm confused
Ahh, I figured it out, the paste function fires before the paste actually happens (which is why it worked when something was already in the field and then selected and pasted) so I had to add a short timeout and it works fine now, thanks for the help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.