473,473 Members | 1,918 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

disable ctrl-v (paste)

I have a code to disable ctrl-v (paste) on the 2nd box. The problem
is that when I type ctrl-v, the text shows, then disappear
after I release ctrl-v. How can I make it not to show in the box. In
VB, I can set keyascii=0 to kill the input. Is there a similar way to
do it in JavaScript? Thanks a lot.

<HTML><head></head><body>
<form name="myForm">
Password: <input type="text"><br>
Comfirm: <input type="text" name="myText"
onKeyUp = "fncKeyStop();"> </form>
<script>
function fncKeyStop(){
if (window.event.ctrlKey){
if (window.event.keyCode == 86) {
document.myForm.myText.value = ""
}
}}
</script></body></HTML>

Chris
Jul 20 '05 #1
10 23477
chirs wrote on 28 Nov 2003:
I have a code to disable ctrl-v (paste) on the 2nd box. The
problem is that when I type ctrl-v, the text shows, then
disappear after I release ctrl-v. How can I make it not to show
in the box. In VB, I can set keyascii=0 to kill the input. Is
there a similar way to do it in JavaScript? Thanks a lot.

<HTML><head></head><body>
<form name="myForm">
Password: <input type="text"><br>
Comfirm: <input type="text" name="myText"
Typo: Comfirm -> Confirm
^ ^
onKeyUp = "fncKeyStop();"> </form>
<script>
The type attribute is mandatory. This should read:

<SCRIPT type="text/javascript">
function fncKeyStop(){
if (window.event.ctrlKey){
if (window.event.keyCode == 86) {
document.myForm.myText.value = ""
You should access forms and form elements using their respective
collections:

document.forms['myForm'].elements['myText'].value = "";
}
}}
</script></body></HTML>


Use both the onkeyup and onkeydown events. That way, it will fire
when a key is pressed once, and when it's released (if held long
enough for the keystroke to repeat).

You should also change the function content to:

function fncKeyStop() {
// Check if the control key is pressed.
// If the Netscape way won't work (event.modifiers is undefined),
// try the IE way (event.ctrlKey)
var ctrl = typeof event.modifiers == 'undefined' ?
event.ctrlKey : event.modifiers & Event.CONTROL_MASK;

// Check if the 'V' key is pressed.
// If the Netscape way won't work (event.which is undefined),
// try the IE way (event.keyCode)
var v = typeof event.which == 'undefined' ?
event.keyCode == 86 : event.which == 86;

// If the control and 'V' keys are pressed at the same time
if ( ctrl && v ) {
// ... discard the keystroke and clear the text box
document.forms['myForm'].elements['myText'].value = '';
return false;
}
return true;
}

....and the intrinsic event bodies to:

<INPUT ... onkeyup="return fncKeyStop()"
onkeydown="return fncKeyStop()">

This works in Internet Explorer and Opera. It should hopefully work
in Mozilla and Netscape too, but I can't test them.

Hope that helps,

Mike

--
Michael Winter
M.******@blueyonder.co.uk.invalid (remove ".invalid" to reply)
Jul 20 '05 #2
In comp.lang.javascript, chirs wrote:
I have a code to disable ctrl-v (paste) on the 2nd box.


Presumably this is to stop users from pasting their email address having
typed it once. If so, may I say how annoyed I would be as a user.
--
Nige

Please replace YYYY with the current year
ille quis mortem cum maximus ludos, vincat
Jul 20 '05 #3
Michael Winter hu kiteb:
type = content-type [p.53] [CI] [p.49]
This attribute specifies the scripting language of the element$BCT(B
contents and overrides the default scripting language. The =========================== scripting language is specified as a content type (e.g.,
"text/javascript"). Authors must supply a value for this attribute.
There is no default value for this attribute. ===================================

I think this specification could do with some proof-reading if your
interpretation is correct.
<META http-equiv="Content-Script-Type" content="text/javascript">


Does this replace the TYPE attribute in the SCRIPT tag?

--
--
Fabian
Visit my website often and for long periods!
http://www.lajzar.co.uk

Jul 20 '05 #4
"Fabian" <la****@hotmail.com> writes:
Michael Winter hu kiteb:
type = content-type [p.53] [CI] [p.49]
This attribute specifies the scripting language of the element
contents and overrides the default scripting language. The

===========================
scripting language is specified as a content type (e.g.,
"text/javascript"). Authors must supply a value for this attribute.
There is no default value for this attribute.

===================================

I think this specification could do with some proof-reading if your
interpretation is correct.


Not really.

There is a "default scripting language" for a page. It can be set
with the META tag shown below. It is the default scripting language
for all scripts on the page.

There is no default *value* for the script tag's type *attribute*.
Furthermore, the type attribute is required, so in practice, the
default scripting language doesn't apply to script elements.

The "default scripting language" and the "type attribute" of script
tags are completely independent. The latter has no default value.
<META http-equiv="Content-Script-Type" content="text/javascript">


Does this replace the TYPE attribute in the SCRIPT tag?


No. It's not about script tags at all. Script tags require the type
attriubte. The intrinsic event attributes (e.g., "onclick") have no
type attribute, and they use the default scripting language of the
page.

Intrinsic events:
<URL:http://www.w3.org/TR/html4/interact/scripts.html#events>
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #5
JRS: In article <lb********************************@4ax.com>, seen in
news:comp.lang.javascript, Nige <uY***@ntlworld.com> posted at Fri, 28
Nov 2003 10:22:38 :-
In comp.lang.javascript, chirs wrote:
I have a code to disable ctrl-v (paste) on the 2nd box.


Presumably this is to stop users from pasting their email address having
typed it once. If so, may I say how annoyed I would be as a user.


It is a password confirm box, AFAICS, which means that using ^V rather
defeats the object of having a confirmation.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> JS maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.
Jul 20 '05 #6
Dr John Stockton hu kiteb:
JRS: In article <lb********************************@4ax.com>, seen in
news:comp.lang.javascript, Nige <uY***@ntlworld.com> posted at Fri, 28
Nov 2003 10:22:38 :-
In comp.lang.javascript, chirs wrote:
I have a code to disable ctrl-v (paste) on the 2nd box.


Presumably this is to stop users from pasting their email address
having typed it once. If so, may I say how annoyed I would be as a
user.


It is a password confirm box, AFAICS, which means that using ^V rather
defeats the object of having a confirmation.


In which case, shouldnt the form object be of type=password? iirc, that
type has cut and paste functions disabled as a 'security' measure.
--
--
Fabian
Visit my website often and for long periods!
http://www.lajzar.co.uk

Jul 20 '05 #7
Fabian wrote on 28 Nov 2003:
Michael Winter hu kiteb:
type = content-type [p.53] [CI] [p.49]
This attribute specifies the scripting language of the
element$BCT(B contents and overrides the default scripting
language. The

===========================
scripting language is specified as a content type (e.g.,
"text/javascript"). Authors must supply a value for this
attribute. There is no default value for this attribute.

===================================

I think this specification could do with some proof-reading if
your interpretation is correct.


It's not an interpretation, that is quoted verbatim. The only edited
sections are the descriptions of the src and defer attributes (which
I removed completely).
<META http-equiv="Content-Script-Type"
content="text/javascript">


Does this replace the TYPE attribute in the SCRIPT tag?


The type attribute is required. That why the specification says (as
you quoted!): "Authors must supply a value for this attribute." The
Content-Script-Type META element or HTTP header is used when parsing
intrinsic events. It is explained in section 18.2.2, Specifying the
scripting language, of the HTML 4.01 specification.

Mike

--
Michael Winter
M.******@blueyonder.co.uk.invalid (remove ".invalid" to reply)
Jul 20 '05 #8
JRS: In article <bq*************@ID-174912.news.uni-berlin.de>, seen in
news:comp.lang.javascript, Fabian <la****@hotmail.com> posted at Sat, 29
Nov 2003 09:07:57 :-
Dr John Stockton hu kiteb:
It is a password confirm box, AFAICS, which means that using ^V rather
defeats the object of having a confirmation.


In which case, shouldnt the form object be of type=password? iirc, that
type has cut and paste functions disabled as a 'security' measure.


You do not RC! Copy and Cut are disabled, but Paste works, in my
browser, in a Password box. But it seems likely that it should be
type=password.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> JS maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.
Jul 20 '05 #9
chirs wrote:
I have a code to disable ctrl-v (paste) on the 2nd box.

[snip]

How do you know that Ctrl-V is the shortcut for Paste? You could be
disabling some other completely different and important feature of the
browser.

Jul 20 '05 #10
David Leverton <u0*****@abdn.ac.uk> writes:
chirs wrote:
I have a code to disable ctrl-v (paste) on the 2nd box.

[snip]

How do you know that Ctrl-V is the shortcut for Paste? You could be
disabling some other completely different and important feature of the
browser.


E.g., it probably also disables Ctrl-Alt-V, which has a function in
Opera. Not one that you would probably want the user to use, though,
as it sends the page to an HTML validator :)

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Greg | last post by:
I am developing an application where I need to secure a workstation for periods of time. I can use BlockInput to stop users from task switching or messing with the keyboard, but I would like to...
3
by: Stefan | last post by:
Hy, i have an app and i must disable this combination: ALT+F4; CTRL+ALT+DEL; CTRL+ESC;ALT+TAB like this: i find something on Internet and i can block ALT+F4 protected override...
4
by: | last post by:
I want to program a application for user login in windows.Now I has some question about disable the system hotkey(c+a+d,alt+tab,win key.etc.) and limit the mouse cursor in winform How can I do it?...
3
by: Kevin Bilbee | last post by:
I need to know the API call to disable the CTRL-ALT-DEL in a C# windows form. We have created a time clock application to run on a tablet PC to replace the windows shell, we are going to hang it...
3
by: Mark | last post by:
Any Visual C++ source code available for disabling the following keys in windows 2000. Alt + Ctrl + Del Ctrl + Esc Windows Key to Remove task bar Function keys (or Alt + Function keys or Ctrl...
3
by: vanya | last post by:
i have been tryin to program(javascript) to disable the following keystroke combinations CTRL+O or CTRL+L Go to a new location (O = 79 L = 76) CTRL+S Save the current page ( S = 83) CTRL+E...
2
by: rn5a | last post by:
In a shopping cart app, assume that a user has placed 4 orders (each order has a corresponding OrderID which will be unique). When he comes to MyCart.aspx, by default, the details of his last order...
14
by: Amar | last post by:
Hi All, I am a newbie to PHP and have the task to create a page using PHP where in that page I need to disable all key operation as well as mouse operation even also the menu operation that...
10
by: thupham | last post by:
Dear all friend, I want disable Ctl+Alt+Del; Ctrl+Esc; Ctrl+tab, Alt+Tab, Start button, ctrl+Alt+Del, lock all keys on the keyboard. Have you ever do it in C#. Help me. Thanks for all reply.
9
by: timw.google | last post by:
Is there a way to disable ctrl-P (print window) in IDLE? I'm editing some python code in IDLE and I keep hitting this by mistake from my years of emacs editing. Thanks in advance.
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.