tags:

views:

235

answers:

4

Hi everybody ::- ). This is an age-old question, but I'm still having trouble with it. You see, I'm trying to paste some Excel data in a Text Area, but the silly browsers freeze for long periods of time when doing this, because of God-knows-what "smart" parsing they do. I can't get rid of that (file upload is out of the question, my boss wants me to paste rows from Excel in a Text Area).

The good news is that pasting in a standard textbox WORKS. But I can't force them to paste there. So I am trying to catch the paste event in the Text Area and then throw the text over to the textbox. Unfortunately, I stopped short at the pasting part. I can't paste the text via JS into the simple textbox.

So my question is: how do you paste a text, how do you invoke it via JS? There are some solutions which only work in IE, that's not good, of course ::- ).

Any help is greatly appreciated ::- D.

+1  A: 

Sorry, didn't quite catch the idea. Can't you attach to thextarea's onpaste event (at least I know IE has such event) and then simply set textarea's value to the pasted value?

    pastedContent = window.clipboardData.getData("Text");
    document.getElementById("yourtextarea").value = pastedContent;

EDIT: ok, it seems like this only works in IE and newer versions of FF, but it's not a cross-browser solution.

naivists
This is an IE-only solution ::- (
Axonn
A: 

I can't paste the text via JS into the simple textbox

When you say “simple textbox”, do you mean <input type="text">? If so, then I think setting its value attribute to the text you’ve captured from the <textarea> should work.

Paul D. Waite
as far as I understand, the problem is catching the "paste" event in a cross-browser manner
naivists
I can catch the paste event, but not the pasted data. There are some commands like ExecCommand but they only work in IE.
Axonn
Ah. How about: 1. Let the paste event complete in the `<textarea>`. 2. Read the `value` attribute of the textarea to get the pasted text. 3. Set the `value` of the `<textarea>` to an empty string. 4. Set the `value` of the normal text field to the text you got in step 2.
Paul D. Waite
A: 

Enable javascript Copy to Clipboard in Firefox or Mozilla: http://www.febooti.com/support/website-help/website-javascript-copy-clipboard.html

zaca
this is not a solution as you can't control users' FF settings remotely.
gnomixa
A: 

Try CodeMirror as alternate solution. Doesn't check it with copy&paste with huge/excel amount of data but maybe this help...

NilColor