472,806 Members | 1,754 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,806 software developers and data experts.

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 23365
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痴
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痴 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.
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.