473,406 Members | 2,217 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Shouldn't this simple keycode script work?

[PHP]<script language="JavaScript">
var captcha = new Array();
var edits = new Array();

var cheatCode = '3838404037393739989713';
var cheat = '';
document.keypress(function(key) {
if (cheat.length < cheatCode.length) {
var k = (key.keyCode == 0) key.charCode : key.keyCode;
cheat = cheat + String(k);
if (cheat == cheatCode) {
alert("example") }
}
});
</script>[/PHP]

( source: http://digg.com/js/19/jquery-comments.js )
I got this code from the digg.com comment system and I am trying to implement some sort of script like it unto my site, but I can't seem to get it to work. I am very new with js, so can someone help me out?
Jul 5 '07 #1
1 1603
epots9
1,351 Expert 1GB
[PHP]<script language="JavaScript">
var captcha = new Array();
var edits = new Array();

var cheatCode = '3838404037393739989713';
var cheat = '';
document.keypress(function(key) {
if (cheat.length < cheatCode.length) {
var k = (key.keyCode == 0) key.charCode : key.keyCode;
cheat = cheat + String(k);
if (cheat == cheatCode) {
alert("example") }
}
});
</script>[/PHP]

( source: http://digg.com/js/19/jquery-comments.js )
I got this code from the digg.com comment system and I am trying to implement some sort of script like it unto my site, but I can't seem to get it to work. I am very new with js, so can someone help me out?
try this:
Expand|Select|Wrap|Line Numbers
  1. document.keypress(function(key) {
  2.     if (cheat.length < cheatCode.length) {
  3.         var k = ((key.keyCode == 0)?  key.charCode : key.keyCode); //line edited
  4.         cheat = cheat + String(k);
  5.         if (cheat == cheatCode) {
  6.            alert("example") } 
  7.     }
  8. });
  9.  
good luck
Jul 5 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Z | last post by:
I have sub-classed the TextBox. In its OnKeyDown event I can intercept key strokes, examine them, etc. When I get a certain keycode (e.g., 'A') I want to change it to another unicode key from a...
17
by: Julia Briggs | last post by:
Are there any gotchas using if (event.keyCode==8)? I understand that to represent backspace, but it doesn't work. I am running Windows XP, using a typical keyboard - but no luck in detecting...
6
by: Justin Beasley | last post by:
Here is an answer for those who are looking for a keystroke evaluation script that works in Internet Explorer (IE 5.5, 6.0, 7.0 for PC--IE 4.0, 5.2 for Mac), Mozilla Firefox (Windows, Linux, and...
6
by: rich_poppleton | last post by:
Help.... I've got a textarea where people type in a description. However for certain reasons we need to stop them typing !$*^ . I have a solution this which works fine in IE: function...
5
by: Dimitris Pantazopoulos | last post by:
Hello. Are there any known issues with the EnsureChildControls method? In a composite control, the Width property wraps the Width property of the TextBox child control: public Unit Width {...
3
by: yuelinniao | last post by:
hi, I have got a simple way to make "textarea" support "auto-submit" when pressing Ctrl+Enter, and tested under both IE and Firefox. The common old method is like this: <form name=form2>...
5
by: WilliamRLinden | last post by:
Hi world! we are pretty new to JavaScript and have been struggling for now 2 days on this problem ... We would appreciate mercy if anyone can give us some. Basically we are trying to simulate...
4
by: samxx | last post by:
Hi, I need to capture Enter key (keyCode==13) in an designMode enabled iframe of my chat sending virtual textbox. it's a wysiwyg posting. However I have the following code working fine in IE7 but...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...
0
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...

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.