Forum Moderators: open

Message Too Old, No Replies

Trigger event when pasting text, not typing

onmouseup and onmousedown don't work

         

itledi

11:20 pm on Jan 1, 2008 (gmt 0)

10+ Year Member



I have a function that I need to trigger in real time when a user adds text to a textarea if they have javascript enabled.

I use ontextdown and ontextup which works great when the user is typing in text, but they don't catch pasting with the mouse. I've tried onmouseup and onmousedown but they don't seem to work.

How do I trigger a function when a user pastes text into my textarea?

And besides typing and pasting with a mouse, are there other input types I should worry about?

rocknbil

7:34 am on Jan 2, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Did you try onchange?

itledi

6:02 pm on Jan 2, 2008 (gmt 0)

10+ Year Member



Thanks, onchange is just what I needed!

itledi

6:08 pm on Jan 2, 2008 (gmt 0)

10+ Year Member



Its interesting, it doesn't seem to work in real time on its own, only running after the user clicks away from that field. However it seems to work in real time if it is paired with onkeyup and onkeydown for the same function in IE 7 and FF.

If I have onchange, onkeydown and onkeyup running, are there any other input methods which I should be concerned about?

Thanks

phranque

6:06 am on Jan 3, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



you can see the description of javascript event behaviors [w3.org] here and note that:
The onchange event occurs when a control loses the input focus and its value has been modified since gaining focus.