/    Sign up×
Community /Pin to ProfileBookmark

How to avoid cu & paste

Hello,

I have two text boxes in asp. I want to avoid cut & paste of data from one text box to another textbox. I know I can do it with javascript, but I don’t kno whow to do it.

Please help.

Thanks
Ceema

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@netbuddyJun 25.2006 — you take the reference to the one box and make the reference in the other box equal to it. it would be done something like this...

document.forms[0].copyofboxname.value = document.forms[0].textboxnametocopy.value;

if you have 1 form with 2 text boxes, one named copyofboxname & another textboxnametocopy, the copyofboxname will be given the content of the other text box.

the html would look like this

<form>

<textearea name='textboxnametocopy'></textarea>

<textearea name='copyofboxname'></textarea>

</form>

if you have 2 text areas and they are in different forms...

<form>

<textearea name='textboxnametocopy'></textarea>

</form>

<form>

<textearea name='copyofboxname'></textarea>

</form>

your code would only differ like so

document.forms[1].copyofboxname.value = document.forms[0].textboxnametocopy.value;

if you add a button or hyperlink, you can make the content copy on a click of a link or button.
Copy linkTweet thisAlerts:
@phpnoviceJun 25.2006 — If you mean you wish to [B][I][U]prevent[/U][/I][/B] cut-n-paste operations... I don't know why you'd want to do that. But, the following works perfectly in IE to prevent every method of selecting text that I could think of -- while still allowing the mouse to click into the textbox for normal data entry:
window.onload = function() {
var obj = document.forms["myFormName"].elements["myTextboxName1"];
obj.onbeforecut = function() { return false };
obj.onbeforepaste = function() { return false };
obj.oncontrolselect = function() { return false };
obj.oncut = function() { return false };
obj.ondblclick = function() { return false };
obj.onmousedown = function() { return false };
obj.onpaste = function() { return false };
obj.onselect = function() { return false };
obj.onselectstart = function() { return false };
return true;
}

Of these, only the [b]onmousedown[/b] and [b]ondblclick[/b] events work to prevent selections via mouse in Mozilla. However, cancelling the [b]onmousedown[/b] event in Mozilla also prevents clicking into the textbox with the mouse. Not good.
Copy linkTweet thisAlerts:
@felgallJun 25.2006 — And disabling Javascript (temporarily) would re-enable the cut and past capability making the entire code pointless. You can't stop your visitors doing what they want when they are on your page- you need to work around whatever they decide to do.
Copy linkTweet thisAlerts:
@ceemaauthorJun 26.2006 — Hello,

Actually, my problem got sdolved by restrcting the ctrl V & right click option.

Thank you for all suggestions

Ceema
Copy linkTweet thisAlerts:
@phpnoviceJun 26.2006 — Actually, my problem got sdolved ...[/QUOTE]
Well, not entirely. But, if you're happy then that is what counts.

Cheers.
Copy linkTweet thisAlerts:
@ceemaauthorJun 27.2006 — Thak you

Ceema
Copy linkTweet thisAlerts:
@phpnoviceJun 27.2006 — You're welcome.

Cheers.
×

Success!

Help @ceema spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...