File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes Problem with text box Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Problem with text box" Watch "Problem with text box" New topic
Author

Problem with text box

swathi veer
Greenhorn

Joined: Nov 27, 2007
Posts: 1
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

Joined: Jan 10, 2002
Posts: 61196
    
  66

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 .


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61196
    
  66

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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with text box