Introduction:
Here
I will explain how to disable cut, copy and paste functionality for the
Textbox using jQuery. In jQuery
we can restrict to user to cut, copy, paste options in Textbox easily by using
simple code.
Description:
In previous articles I explained disable cut, copy and paste options for the textbox using JavaScript, jQuery Zoom Image on mouse over, jQuery calculate page load time, jQuery Scrollable div with fixed header and many articles relating to jQuery, JavaScript, SQL Server, asp.net, gridview, C#, VB.NET.
In previous articles I explained disable cut, copy and paste options for the textbox using JavaScript, jQuery Zoom Image on mouse over, jQuery calculate page load time, jQuery Scrollable div with fixed header and many articles relating to jQuery, JavaScript, SQL Server, asp.net, gridview, C#, VB.NET.
To disable cut, copy and paste functionality
for the Textbox we need to write the code like as shown below
<script type="text/javascript">
$(function()
{
$('#txtName').bind("cut copy paste", function(e) {
e.preventDefault();
});
});
</script>
|
If you want to see it in complete example write the
code like as shown below
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Disable Cut, Copy and Paste Options in textbox using jQuery</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
$(function()
{
$('#txtName').bind("cut copy paste", function(e) {
e.preventDefault();
});
});
</script>
</head>
<body>
<div>
<input type="text" id="txtName" />
</div>
</body>
</html>
|
Live
Demo
For live demo try to enter text in textbox
Enter Text:
|
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
|
|||
9 comments :
plz give some realtime example with solution on WCF it will help to prepare for interview .
i think its not working as i tried to do cut,copy with other textboxes in this page...same result i got...and when i selected text in the textbox...the cut and copy options were available...what is the code actually supposed to do?
It's working fine. i have written code only for Live Demo Textbox not for all the textboxes in this page. Please test completly before post comments like not working...
Hi Suresh
How to add multiple text boxes to that function.
Could you please reply.
Helpful for me ...thank u
sir how to change this into asp.net control....
pls respond me
sir,I need explanation for the above code because i selected the text and gave right click and then i cut the data and again copied it there so cut,paste r working
Its working fine..@venky just do like this for asp controls..
$(function () {
$("#<%=TextBox10.ClientID %>").bind("cut copy paste", function (e) {
e.preventDefault();
});
});
In the abouve 'TextBox10' is the id of asp textbox
plz explain the above code
Note: Only a member of this blog may post a comment.