Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. javascript for textbox that accept only numbers

javascript for textbox that accept only numbers

Scheduled Pinned Locked Moved Web Development
javascripthelpquestion
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DineshSharmain
    wrote on last edited by
    #1

    hi i have writen javascript to accept only numbers for a textbox function validate() { var e = window.event.keyCode; if(!((e>=96 && e<=105)||(e>=48 && e<=57))) return false; } i m calling this function on keyup event of textbox but problem is that after returning false it write the char in textbox. how can i do that.... Thanks

    Dinesh Sharma

    R K 2 Replies Last reply
    0
    • D DineshSharmain

      hi i have writen javascript to accept only numbers for a textbox function validate() { var e = window.event.keyCode; if(!((e>=96 && e<=105)||(e>=48 && e<=57))) return false; } i m calling this function on keyup event of textbox but problem is that after returning false it write the char in textbox. how can i do that.... Thanks

      Dinesh Sharma

      R Offline
      R Offline
      RichardGrimmer
      wrote on last edited by
      #2

      DineshSharmain wrote:

      keyup event

      Try keydown / keypress instead - keydown will prob stop it if you return false...

      "Knock me down, I'll get straight back up again, I'll come back stronger than a powered up pacman" (Lilly Allen / Kaiser Chiefs)

      D 1 Reply Last reply
      0
      • R RichardGrimmer

        DineshSharmain wrote:

        keyup event

        Try keydown / keypress instead - keydown will prob stop it if you return false...

        "Knock me down, I'll get straight back up again, I'll come back stronger than a powered up pacman" (Lilly Allen / Kaiser Chiefs)

        D Offline
        D Offline
        DineshSharmain
        wrote on last edited by
        #3

        Thanks for your interest... i have tried all the events but still it display the char. that i don't want. please suggest me if any other way to accept only numeric. these textboxes are generating at run time. :confused:

        Dinesh Sharma

        C 1 Reply Last reply
        0
        • D DineshSharmain

          Thanks for your interest... i have tried all the events but still it display the char. that i don't want. please suggest me if any other way to accept only numeric. these textboxes are generating at run time. :confused:

          Dinesh Sharma

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          It's all about the code that you use for the key press. It also matters if you're using FF or IE. I suggest googling, there are tons of examples on the web on how to do this.

          Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

          1 Reply Last reply
          0
          • D DineshSharmain

            hi i have writen javascript to accept only numbers for a textbox function validate() { var e = window.event.keyCode; if(!((e>=96 && e<=105)||(e>=48 && e<=57))) return false; } i m calling this function on keyup event of textbox but problem is that after returning false it write the char in textbox. how can i do that.... Thanks

            Dinesh Sharma

            K Offline
            K Offline
            krsasi
            wrote on last edited by
            #5

            Hi, Instead of calling this method in keyup event, call it in keypress event it will not allow to you enter anything except numbers. Regards, kr.sasi

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups