0

Hello Fellows :)

I am trying to find a way to get more than one characters pasted on html text field (input type=text), using onkeydown or onkeypress, I am NOT interested in onkeyup(it works), so please do not suggest me this solution. Also I am not interested in Jquery, I do not like to use it. I need solution to work with all browsers.

I am able to do that if you type one character, by taking the character of the event, but till now I am unable to get group of characters come from the paste (ctrl+V) or by mouse.

You can look at Facebook search menu that shows auto complete results, it works on events: onkeydown and onkeypress and you notice that you get the result before you release your finger, try to paste something (more than one character) and you get the result before releasing finger, how? Onkeypress and onkeydown do not show first thing you paste or type because they happen before the text being added to text field.

If you want to understand what I want more, please check my code below:

<input type="text" id="targetTextField" onkeydown="CapturePastedString(this.id)" />
<script>
function CapturePastedString(id){
    
    var targetTextField=document.getElementById(id);
  
    // below I need to capture the pasted string like:
    var pasted_string= function(){.....}
    
    targetTextField.value=pasted_string;

}
</script>

Any help would be so thankful, because since long time I am trying but cannot find solution yet.

Edited by Moderns: n/a

3
Contributors
9
Replies
10
Views
6 Years
Discussion Span
Last Post by Moderns
0

Till now I am unable to do it :( Any hints will be so thankful!

0

You may read this post http://www.daniweb.com/web-development/javascript-dhtml-ajax/threads/385613 and just look at how he controls the keyboard event. You need to modify the part where the key code is being checked. That should do it.

Actually it's not what I want :( I am looking to paste string (with more than one character), and the post you provided explains about typing one character which I already know. I hope you got me, I mentioned that in my original post.

Thanks.

Edited by Moderns: n/a

0

OK, not really. What you may want is to read the text value from the field & add the character you capture from the event. Now you can parse the string you want? For example, the field already has value "myO" and then you type in "L" using keydown. The key event capture the "L" for you. Then, in your key event, you get the value from the field which could be "myO" and then concatenate with the character you just capture to get "myOL" and do something with it?

0

OK, not really. What you may want is to read the text value from the field & add the character you capture from the event. Now you can parse the string you want? For example, the field already has value "myO" and then you type in "L" using keydown. The key event capture the "L" for you. Then, in your key event, you get the value from the field which could be "myO" and then concatenate with the character you just capture to get "myOL" and do something with it?

But I want to use pasting of string "hello" using Ctrl+V, so how can I add it to old value of text box? Facebook is doing that, but how??

0

If you want to see how FB does it, view the source (especially using Firebug of FF to see many other things). Also, please keep in mind that FB has its own implementation in many ways that are not the same as in public. You could try to accomplish as they are doing, but don't expect to get the exactly same result.

0

If you want to see how FB does it, view the source (especially using Firebug of FF to see many other things). Also, please keep in mind that FB has its own implementation in many ways that are not the same as in public. You could try to accomplish as they are doing, but don't expect to get the exactly same result.

If I can find the solution in the FB codes, then I will not come and ask here :) I couldn't understand because million lines of javascript... I hope someone will give me serious hint here.. I am waiting...

0

it is not compatible with all browsers and doesnt have standards, I am really surprise why cannot find solution yet, FB is not doing magic but I failed to implement that :(

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.