olerag
11-07-2003, 08:18 AM
The following code is from a text that only permits numerics
to be entered. Here's the code...
function numeralsOnly(evt) {
evt = (evt) ? evt : event;
var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0)));
if (charCode > 31 && (charCode < 48 || charCode > 57)) {
alert("Enter numerals only in this field.");
return false;
}
return true;
}
The code is fired with an "onkeypress" event on the form
object.
The problem I have is discerning the "jumbled" code in
the instantiation of the "charCode" variable. Could someone
please offer a nice interpretation how this variable is
obviously retaining what character is being pressed.
Another question. If I wanted to test to permit only the
first character in the string to be signed (permitting either a
"-" or "+" sign, how would this affect the code presented above?
Thanx for any/all assistance...
to be entered. Here's the code...
function numeralsOnly(evt) {
evt = (evt) ? evt : event;
var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0)));
if (charCode > 31 && (charCode < 48 || charCode > 57)) {
alert("Enter numerals only in this field.");
return false;
}
return true;
}
The code is fired with an "onkeypress" event on the form
object.
The problem I have is discerning the "jumbled" code in
the instantiation of the "charCode" variable. Could someone
please offer a nice interpretation how this variable is
obviously retaining what character is being pressed.
Another question. If I wanted to test to permit only the
first character in the string to be signed (permitting either a
"-" or "+" sign, how would this affect the code presented above?
Thanx for any/all assistance...