Question

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.

Was it helpful?

Solution

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;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top