I have a JavaScript function that is not working now that I put in a new one under it. Here is what is in the head of my document.
<head>
<link rel="stylesheet" href="9j3nz/style.css" type="text/css">
<script src="jquery.js"></script>
<script src="processing.js"></script>
<script type="text/javascript">
function isNumberKey(evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57))
return false;
return true;
}
</script>
<script type="text/javascript">
function stopRKey(evt) {
var evt = (evt) ? evt : ((event) ? event : null);
var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
if ((evt.keyCode == 13) && (node.type=="text"))
$("label#enter_error").show();
{return false;}
}
document.onkeypress = stopRKey;
</script>
</head>
Everything is working fine except the isnumberkey function that was previously working. Nothing has changed in my HTML. Any help is appreciated. Thanks!
I am calling the isnumberkey function as follows:
onkeypress="return isNumberKey(event)"
What might be keeping this from working? It has only started acting up since I put in the Stop Enter Key function.
EDIT:
After removing the Stop Enter Key function the isnumberkey event works again. I think they are interfering with each other some how.
Seems like your stopRKey is always returning false which could be blocking your isNumberKey.
Try re-arranging your parens.
Should be
Update: There are two ways of using the if statement.
You can call
ifwith a single operation: eg.or you can call an
ifstatement with a block of codeSince your parens were out of order your code was only executing the
show()if the user pressed enter and then continued processing the remaining code. So return false was always called.