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

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -