0

Is there a way to disable the paste (control V) into a text box using javascript/jquery for IE?

I do not have access to the markup unfortunately or I would use onPaste="return false". Can it be attached with Jquery?

If it cannot be disabled at least is there a way to detect it so that when the paste event occurs just remove the text from the input text box.

<input type="text" maxlength="" size="25" value="Enter letters here" name="TEXTBOX___97___470GCPC___31" autocomplete="off">
user357034
  • 10,731
  • 19
  • 58
  • 72

1 Answers1

5

Try

$('input[name="TEXTBOX___97___470GCPC___31"]').bind('paste', function(){return false;})

There is no need to use jQuery though, as you could just set the onpaste handler.

var input = document.getElementsByName('TEXTBOX___97___470GCPC___31')[0];
if (input)
   input.onpaste = function(){return false;};

Note that this event may not fire on some browsers (e.g. Opera). Also, see this question: Disable Copy/Paste into HTML form using Javascript on why you should not disable pasting.

Community
  • 1
  • 1
kennytm
  • 510,854
  • 105
  • 1,084
  • 1,005
  • Duh, why didn't I think of that. I looked and the events that could be used in Jquery doc http://api.jquery.com/bind/ and http://api.jquery.com/category/events/ and didn't see it so I thought it didn't support it. I should of tried it first. THX – user357034 Sep 11 '10 at 19:18
  • Thanks for the added info but I only needed it for IE as the other script I am using for input validation seems to take care of the other browsers just not IE for some reason – user357034 Sep 11 '10 at 19:22
  • Firefox didn't get the `paste` event until version 3.0. – Tim Down Sep 12 '10 at 15:28