5

in html and javascript, I can use keyup, focus, blur to detect most of the content changes in a text input, however if the user do a copy and paste into the text input, how do I capture this change? The issue here is that the input is already in focus when user paste into it.

3 Answers 3

4

You could capture the paste event (http://www.quirksmode.org/dom/events/cutcopypaste.html)

$("#myinput").bind("paste",function(){
    //code here
})
Sign up to request clarification or add additional context in comments.

1 Comment

That's nice! unfortunately paste is not supported in all browsers esp. FF3
4
$("#myinput").change(function(){
    // whatever you need to be done on change of the input field
});

// Trigger change if the user type or paste the text in the field
$("#myinput").keyup(function(){
    $(this).change();
});

// if you're using a virtual keyboard, you can do :
$(".key").live('click',function(){
    $("#myinput").val($("#myinput").val()+$(this).val());
    $("#myinput").change(); // Trigger change when the value changes
});

1 Comment

change event only triggers when you leave that input field, not on every single keypress. keyup is a mess since if you're pressing tab key - it'll trigger event on the next element, the one you'll tab into (at least in firefox 5.0)! Also - you're saying that keyup event will be triggered on paste? - that's only correct if you''ll paste via keyboard and not from browser context menu.
3

the textbox has an OnChange event that fires when a) the text box loses focus AND the value within the text box has changed.

2 Comments

unfortunately, this doesn't work for paste, because the focus is not lost when user pastes something into the text box
you're not catching the PASTE, you're catching the fact that the value has been modified when the user leaves the textbox.

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.