I have an issue with the onpaste event in JS. I need to copy the clipboard content into two text boxes by splitting it into half. I am using the code below:
function paste(){
document.getElementById("txt1").value = clipboarddata.substr(0,2);
document.getElementById("txt2").value = clipboarddata.substr(2,4);
}
this function is called on the onpaste
event. The content gets pasted but after the function the entire string is again paste in the box into which the data was paste.
Can I by any chance cancel the event by using cancelbubble
etc to cancel the event in the paste()
function?
I know this is a bit late, but here is a way of doing that for anyone that looks for this:
After you do what you have to do, You have to
return false;
This will prevent the default handler from running.Here's a demo:
HTML
Javascript
jsfiddle demo