开发者

Detecting Drop Event in Input (Text) using Javascript

开发者 https://www.devze.com 2022-12-09 16:47 出处:网络
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, lef

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 ev开发者_Go百科ent...

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.


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;
0

精彩评论

暂无评论...
验证码 换一张
取 消