On Fri, 2009-07-17 at 08:45 -0700, Caio Landau wrote: > So let me get it, key's code numbered between (and including) 48 and > 57 are numbers?
I used an "alert" dialog to determine the keycodes, you could probably also use an ascii chart. You also may want to include the codes for: backspace arrow keys delete etc. Cheers, > > On Jul 17, 11:18 am, Matt Zagrabelny <mzagr...@d.umn.edu> wrote: > > On Thu, 2009-07-16 at 16:12 -0700, Caio Landau wrote: > > > Well, that a simple question, I hope. I have an input (<input > > > type="text" />) on my page, and I want it to only accept numbers, so > > > if the user types anything that's not a number, it will be removed > > > instantly. > > > > > A simplified example just to illustrate: > > > > > <body> > > > <input type="text" name="numbers" /> <!-- I want this input to accept > > > only numbers --> > > > </body> > > > > This works for me... > > > > <html> > > <head> > > <script language="javascript" type="text/javascript" > > src="/usr/share/javascript/jquery/jquery.js"></script> > > <script language="javascript" type="text/javascript"> > > $(function() { > > $('#numbersonly').keypress( > > function(event) { > > return ((event.which >= 48) && (event.which <= 57)); > > } > > );}); > > > > </script> > > </head> > > <body> > > <input id="numbersonly" name="first_name"/> > > </body> > > </html> > > > > Cheers, > > > > -- > > Matt Zagrabelny - mzagr...@d.umn.edu - (218) 726 8844 > > University of Minnesota Duluth > > Information Technology Systems & Services > > PGP key 1024D/84E22DA2 2005-11-07 > > Fingerprint: 78F9 18B3 EF58 56F5 FC85 C5CA 53E7 887F 84E2 2DA2 > > > > He is not a fool who gives up what he cannot keep to gain what he cannot > > lose. > > -Jim Elliot > > > > signature.asc > > < 1KViewDownload -- Matt Zagrabelny - mzagr...@d.umn.edu - (218) 726 8844 University of Minnesota Duluth Information Technology Systems & Services PGP key 1024D/84E22DA2 2005-11-07 Fingerprint: 78F9 18B3 EF58 56F5 FC85 C5CA 53E7 887F 84E2 2DA2 He is not a fool who gives up what he cannot keep to gain what he cannot lose. -Jim Elliot
signature.asc
Description: This is a digitally signed message part