HighDots Forums  

How do you get the results of a paste?

Javascript JavaScript language (comp.lang.javascript)


Discuss How do you get the results of a paste? in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Mark Thomas
 
Posts: n/a

Default How do you get the results of a paste? - 02-26-2004 , 02:19 PM






I need to get text pasted into a form field at the time it was pasted.
The value of the field is still blank in the onpaste handler. The
onchange event is not triggered until the input loses focus, and I
want to execute a function before that happens. How can I do that?

Thanks.

Reply With Quote
  #2  
Old   
Ivo
 
Posts: n/a

Default Re: How do you get the results of a paste? - 02-26-2004 , 05:27 PM






"Mark Thomas" <mrt (AT) thomaszone (DOT) com> wrote

Quote:
I need to get text pasted into a form field at the time it was pasted.
The value of the field is still blank in the onpaste handler. The
onchange event is not triggered until the input loses focus, and I
want to execute a function before that happens. How can I do that?
Use onpaste (IE only as far as I am aware):
<input type="text" onpaste="fnPaste(this)">
<script etc.>
function fnPaste(el){
event.returnValue=false;
// stops default action
a=window.clipboardData.getData('Text');
// what they think they were about to paste
el.value = a.replace(/ /g,'_');
// or whatever you would like to do
}
</script>






Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.