How do you get the results of a paste?

M

Mark Thomas

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.
 
I

Ivo

Mark Thomas said:
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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,438
Messages
2,571,699
Members
48,796
Latest member
Greg L.
Top