javascript - Tracking if backspace or delete key is pressed in an input field -
i wondering how can track if users hit backspace or delete key in input field. afterwhich add variable called count each time buttons pressed. have code not seem work; great appreciated, thank you.
var count = 0; var input = document.getelementbyid('display'); input.onkeydown = function() { var key = event.keycode || event.charcode; if( key == 8 || key == 46 ) count++; return false; };
multiple lines inside conditional or loop, etc. need wrapped in braces:
if( key == 8 || key == 46 ) { count++; return false; }
you want add default return true
last line differentiate whether entered if or not well.
Comments
Post a Comment