Tuesday, 22 October 2013

jQuery to block paste in a textbox

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Block Paste</title>
    
    <script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    
     <script type="text/javascript">
          // hook to the document ready function
         $(document).ready(function () {
             
           // bind the paste operation
           $('#<%=tbAccept.ClientID%>').bind('paste',
                function (e) {
                     // prevent the default operation
                  e.preventDefault();
                    // warn the user
                     alert("Paste disabled in this textbox");
               });

          });
      
</script> </head> <body> <form id="form1" runat="server"> <div> Please enter your name: <!-- the textbox you want to disable paste on --> <asp:TextBox runat="server" ID="tbAccept"> </asp:TextBox> </div> </form> </body> </html>

No comments:

Post a Comment