Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with text box

 
swathi veer
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm using struts. In one of my pages there is one text box, where we must not allow user to enter values other than numerics. For that I wrote this java script. This was working fine . The problem is , my QA found that
thay can paste some characters into that. Can any one help ....


function allowOnlyIntegers(evt) {
evt = (evt) ? evt : window.event
var c = (evt.which) ? evt.which : evt.keyCode
if (c > 31 && (c < 48 || c > 57)) {
return false
}
return true
}

Thanks in advance

Swathiveer
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65115
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please be sure to use UBB code tags when posting code to the forums. Unformatted code is extermely hard to read and most people will just go elsewhere. Please read this for more information.

You can go back and change your post to add code tags by clicking the .
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65115
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I assume that the function you posted is established as a keypress event handler? This sort of detail is important to include in your posts. Please read this for more information.

If so, then of course the function will never be called unless the user is typing into the field.

So, how else can you detect when it's time to perform a field validation? What other events can you listen for in order to check the value?
[ November 27, 2007: Message edited by: Bear Bibeault ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic