473,399 Members | 3,603 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,399 software developers and data experts.

Capture Key, only allow numbers

I have this function:

function ValidateIntKey()
{
var Key;
var CharKey;
Key = event.keyCode;
alert(Key);

//CharKey = String.charCodeAt(Key);
alert(String.fromCharCode(Key));
CharKey = String.fromCharCode(Key)
if (!isInteger(CharKey))
{
alert("no integer");
}
}

Where i have "alert("no integer");" i want to make the keyCode null so
that it doesn't reach the textbox this function is attached to. How
do i do this? I tried:

event.keyCode = 0; but this did not work. Any other ideas?
Jul 23 '05 #1
9 4686
On 1/10/04 6:41 pm, Leroy wrote:
I have this function:

function ValidateIntKey()
{
var Key;
var CharKey;
Key = event.keyCode;
alert(Key);

//CharKey = String.charCodeAt(Key);
alert(String.fromCharCode(Key));
CharKey = String.fromCharCode(Key)
if (!isInteger(CharKey))
{
alert("no integer");
}
}

Where i have "alert("no integer");" i want to make the keyCode null so
that it doesn't reach the textbox this function is attached to. How
do i do this? I tried:

event.keyCode = 0; but this did not work. Any other ideas?


Has it occurred to you that this function is going to annoy the crap out of
everyone? We all make typing mistakes from time to time; that's why
keyboards have a delete key. If your web page throws an alert at me every
time I make a tiny slip of the finger then I'm not going to stay there very
long.

Why not do your form validation the old-fashioned way and check for integers
in an onsubmit() event?

Phil

--
Philip Ronan
ph***********@virgin.net
(Please remove the "z"s if replying by email)
Jul 23 '05 #2
Lee
Philip Ronan said:

On 1/10/04 6:41 pm, Leroy wrote:
I have this function:

function ValidateIntKey()
{
var Key;
var CharKey;
Key = event.keyCode;
alert(Key);

//CharKey = String.charCodeAt(Key);
alert(String.fromCharCode(Key));
CharKey = String.fromCharCode(Key)
if (!isInteger(CharKey))
{
alert("no integer");
}
}

Where i have "alert("no integer");" i want to make the keyCode null so
that it doesn't reach the textbox this function is attached to. How
do i do this? I tried:

event.keyCode = 0; but this did not work. Any other ideas?


Has it occurred to you that this function is going to annoy the crap out of
everyone? We all make typing mistakes from time to time; that's why
keyboards have a delete key. If your web page throws an alert at me every
time I make a tiny slip of the finger then I'm not going to stay there very
long.

Why not do your form validation the old-fashioned way and check for integers
in an onsubmit() event?


Absolutely! Even if you do away with the alert and simply block
all non-integer keystrokes, you're going to send people away angry.

Imagine that I'm trying to type "123" and accidentally hit "12w".
I may not even be looking at the screen when I realize that I've
hit the wrong key and automatically hit the backspace. If you've
blocked the "w" keystroke, I've just deleted the "2".

Jul 23 '05 #3


I am not looking for an analysis of what i am doing. I am just looking
for an answer to my problem, please.

I understand what everyone is saying about the annoyance, but i have a
reason for doing this and it is not relevant to getting an answer to my
problem.

Can someone please tell me how i can intercept a keystroke an replace it
with nothing? Thank you in advance

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #4


Found the answer.

function ValidateIntKey()
{
var Key;
var CharKey;
Key = event.keyCode;
//alert(String.fromCharCode(Key));
CharKey = String.fromCharCode(Key)
if (!isInteger(CharKey))
{
event.returnValue = false;
}
}

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #5


Found the answer.

function ValidateIntKey()
{
var Key;
var CharKey;
Key = event.keyCode;
//alert(String.fromCharCode(Key));
CharKey = String.fromCharCode(Key)
if (!isInteger(CharKey))
{
event.returnValue = false;
}
}

This only works on keypress, not keyup or keydown.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #6
In article <86**************************@posting.google.com >,
st************@intercim.com (Leroy) wrote:
I have this function:

function ValidateIntKey()
{
var Key;
var CharKey;
Key = event.keyCode;
alert(Key);

//CharKey = String.charCodeAt(Key);
alert(String.fromCharCode(Key));
CharKey = String.fromCharCode(Key)
if (!isInteger(CharKey))
{
alert("no integer");
}
}

This is a feature of IE. When you do the alert, IE looses track of what
key was pressed.

Robert
Jul 23 '05 #7
"Leroy Stanislowski" <st************@intercim.com> wrote in message news:41**********************@news.newsgroups.ws.. .


I am not looking for an analysis of what i am doing. I am just looking
for an answer to my problem, please. *** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Good luck Leroy

--
George Hester
__________________________________
Jul 23 '05 #8
Leroy Stanislowski wrote:
I am not looking for an analysis of what i am doing. I am just looking
for an answer to my problem, please.


Your problem is that you have not pressed the Power button
of the computer you are abusing. You're welcome.
PointedEars
--
Damnit Fraser! If you're gonna drop a guy, you gotta say something like
"Ray, I'm gonna drop ya."
Jul 23 '05 #9
Thomas 'PointedEars' Lahn wrote:
Leroy Stanislowski wrote:

I am not looking for an analysis of what i am doing. I am just looking
for an answer to my problem, please.

Your problem is that you have not pressed the Power button
of the computer you are abusing. You're welcome.


And to think it only took you 13 days to come up with that garbage. Wow.
You are starting to really impress me. Wanna buy some Ocean Front
property in Arizona? I have a deal just for you........

P.S. ExLax might be of help to you, since you are full of s**t.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #10

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

Similar topics

0
by: JerryB | last post by:
i am looking for a way to capture some data from a web DB that is set up to only allow a user to view one page of a query at a time or to print the entire query. i don't want to print and retype...
3
by: Me Mine | last post by:
i, I have trying to code a small console app that will allow a user to select a window and then create a screen capture of the window. I haven't been able to figure out how to do the screen...
5
by: TerryWilson | last post by:
I am developing a web based service tool using asp.net that we will distribute with our product. This service tool will be used for remotely configuring the product, problem determination, etc. ...
2
by: Juan Romero | last post by:
Guys, I am trying to capture the desktop screen (everything). I am having a problem with the "CreateCompatibleBitmap" API call. For some reason the function is creating a 1x1 pixels bitmap...
11
by: tlyczko | last post by:
Hello Rob B posted this wonderful code in another thread, http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/c84d8538025980dd/6ead9d5e61be85f0#6ead9d5e61be85f0 I could not...
4
by: gwhite1 | last post by:
I use this code to capture a screen in a regular VB 2005 windows app. It works great! I found the code in google. But when I create a windows service it does not capture the screen. It only...
3
by: JeffDotNet | last post by:
I wrote a small data processing application that writes a summary of several hundred files. I use drag and drop on a panel (Panel1) to grab the absolute path to each of these files. Then I begin...
9
by: aljosa | last post by:
i'm trying to capture video from camera/webcam using python. so far i haven't found any library that would allow me to do that. cross-platform solution related to SDL/pygame would be nice but a...
2
by: dumbledad | last post by:
Hi All, I'm using ASP.Net web services to provide the logic required for a Flash based prototype. The Flash and the ASP .Net run together on the client machine. One of the functions I'd like to...
0
by: amyl | last post by:
I have a 32 bit number "3515261219" that really contains four 8 bit numbers. 11010001 10000110 10100001 00100011 Is there a way to capture the bits that are shifted out of the number when you...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
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.