I am running under Ubuntu Linux. I have a JavaScript function that edits data as it is being entered by a user. The data is edited using the $,.-+ characters.
<script type="text/javascript" src="/static/jquery/jquery-1.4.2.js"></script>
<script type="text/javascript" src="/static/jquery/jquery-ui-1.8.1.custom.min.js"></script>
<script type="text/javascript" src="/static/js/json_sans_eval.js"></script>
<script type="text/javascript" src="/static/edit.js"></script>
<script type="text/javascript" src="/static/cdpUtils.js"></script>
function onkeypressFunc (event)
{
var data = event.target.value;
var keyNum = event.which;
var keyCode = event.keyCode;
var shiftKey = event.shiftKey;
var charCode = event.charCode;
if (keyNum == 9 && keyCode == 9) // this works when using keydown
{
I have been testing keyNum for months and the + key has been 43 and the - key has been 45.
Today I noticed that I can no longer enter a negative number using the - key on the main keyboard. After checking, I can see that the keyNum code is now 173. Is there any explanation for the change. I believe that this same thing occurred several months ago and I had to change the software then to look for the new codes.
This has only been tested on Firefox 22.0.
I think it's a bug(at least a compatibility Issues) for firefox, as
String.fromCharCode(173)
outputs ""
Normally the keypress code is more reliable, e.g. for char '+', you can press shift(16) and =(187) , or the +(107) on the number panel, but the keypress keyCode will always be 43.
Also, as you use jQuery, event.which is prefered.
event.which property normalizes event.keyCode and event.charCode
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With