views:

299

answers:

2

Hi all,

Atleast defining my problem is simple... I have a Input control (Text) and a javascript function, which truncates the Text in the input control to 15 characters. ie if the length exceeds the limit, left(text,15) is set back to the control.

This is handled through onkeyup event...

Now, when user drag and drops the text directly into the Input control, the event is not fired as no keyboard is involved. In that case, which event fires... or how do I execute the javascript function in that scenario.

+1  A: 

Except for onkeyup, try handling onmouseup too. It should trigger when you release your mouse button in the input-box (in other words, when you drop the text).


Edit: Apparently onmouseup only triggers if the mouse button was clicked in the input-box too, but onfocus should trigger when the input-box receives focus when you're dropping the text.

Example:

document.getElementById('elementid').onkeyup  = function()
{
   // Restrict value length to 15 characters
};
document.getElementById('elementid').onfocus = document.getElementById('test').onkeyup;
Morningcoffee
onmouseup event fires otherwise when a mouse button is released on the Text Box but not when drag and drop happens... I dont know why.
The King
Cool... This works really well.
The King
+1  A: 

Also may be useful following link:

http://stackoverflow.com/questions/441631/how-to-detect-right-mouse-click-paste-using-javascript

Anatoliy