Wednesday, February 6, 2013

Disable cut, copy and paste in textbox using jquery, javascript

Sometimes we need to restrict the user to cut or copy the content from TextBox and also restrict to paste the content into TextBox. It is very easy to do this using Java Script as well as using Jquery. Here I will show you both the methods i.e. using Java Script and using jQuery.

 

Using Java Script

<asp:TextBox ID="txtByJavaScript" runat="server" oncut="return false;" oncopy="return false;" onpaste="return false;"></asp:TextBox>

 

Using Jquery

<script type="text/javascript">
 $(document).ready(function () {
   $('#txtByJquery').bind('cut copy paste', function (e) {
    e.preventDefault(); //disable cut,copy,paste
   });
 });
</script>

That's it. :)

No comments:

Post a Comment

If You Enjoyed This Post Please Take 5 Seconds To Share It.

^ Scroll to Top hgpromo