|
-
Jan 8th, 2003, 11:48 AM
#1
Thread Starter
Fanatic Member
JSCRIPT - check to see if first num is 0
Using Jscript I want to prevent the user from entering in 0 as the first number...
So if the user enters 0 as the first number then a msg appear
-
Jan 8th, 2003, 04:30 PM
#2
Fanatic Member
First of all, where should the user enter in the numbers? If you really want a clear answer, you should learn to ask clear questions as well.
Suppose if it's a textbox in a form (input type=text), then you can write an event handler for the onkeypress event: onkeypress="eventHandler(event)". Then in the function eventHandler you can extract the .keyCode property (.which property for NS 4) from the event object, and there you can check what key the user hes pressed. (The keycode is the ASCII code) Pressing the zero will return keycode 48. If the user indeed has entered 0 as the first character for the value, then you can just return false. In that case the key press is canceled. There's no much need to notify the user imho; it should be pretty clear if the user doesn't see the zero showing up. I think it's annoying to click alerts away for every petty warning.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|