Jun 23, 2004 #1 vasilek Programmer Joined Jan 5, 2003 Messages 99 Location US Hello. This was probably asked before, but it doesn't come up on the top of search results. How to check if the value in the field is a number? I would like to prohibit entering everything but numbers into quantity field. Thank you.
Hello. This was probably asked before, but it doesn't come up on the top of search results. How to check if the value in the field is a number? I would like to prohibit entering everything but numbers into quantity field. Thank you.
Jun 23, 2004 #2 Supra Programmer Joined Dec 6, 2000 Messages 422 Location US Try this: Code: <script> <!-- function KillLetters() { if (event.keyCode < 48 || event.keyCode > 57) { event.keyCode = 0; } } //--> </script> <input type="text" onkeyup="KillLetters()"> Upvote 0 Downvote
Try this: Code: <script> <!-- function KillLetters() { if (event.keyCode < 48 || event.keyCode > 57) { event.keyCode = 0; } } //--> </script> <input type="text" onkeyup="KillLetters()">
Jun 23, 2004 #3 GUJUm0deL Programmer Joined Jan 16, 2001 Messages 3,676 Location US You can also try: Code: <script> function onlyNum() { var Gm = document.form1; if(isNaN(Gm.field1.value)) { alert("Only numbers please"); return false; } } </script> ... ... <input type="text" name="field1" onBlur="return onlyNum();"> ____________________________________ Just Imagine. http://www.imajinarts.com Upvote 0 Downvote
You can also try: Code: <script> function onlyNum() { var Gm = document.form1; if(isNaN(Gm.field1.value)) { alert("Only numbers please"); return false; } } </script> ... ... <input type="text" name="field1" onBlur="return onlyNum();"> ____________________________________ Just Imagine. http://www.imajinarts.com
Jun 24, 2004 #4 BillyRayPreachersSon Programmer Joined Dec 8, 2003 Messages 17,047 Location GB I would go with GUJUm0deL's solution, as Supra's will not let you enter valid numbers such as "1.5", "2.3", etc. Dan Upvote 0 Downvote
I would go with GUJUm0deL's solution, as Supra's will not let you enter valid numbers such as "1.5", "2.3", etc. Dan