Results 1 to 2 of 2

Thread: JSCRIPT - check to see if first num is 0

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2002
    Location
    Hampton Beach
    Posts
    513

    Question 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

  2. #2
    Fanatic Member riis's Avatar
    Join Date
    Nov 2001
    Posts
    551
    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
  •  



Click Here to Expand Forum to Full Width