Is there an opposite function of preventDefault() in JavaScript?

I think the problem you are having is that you are not looking for the delete key. Preventdefault does not cancel the event handler all together. But with your code once you hit the maximum length of your field the user will no longer be able delete any characters because the delete keypress is being cancelled.

The reason it works in IE is because IE does not fire the keypress event for delete, end, enter, escape, function keys, home, insert, pageUp/Down and tab. In Safari the keycode for delete is incorrect in the keypress event.

For these reasons I have a twofold suggestion; first, use the keydown event instead so that you get the correct keycodes.

Second, look at the keycode and if it is delete or backspace then don't preventDefault.

if ((event.keyCode != 46 && event.keyCode != 8) || input_length > (wordNum - 1)) {
    return false;
} else {
    return true;
}

simply use return true; at the end of your eventHandler. That would bubble up the event to the browser.


Doesn't look like it, https://developer.mozilla.org/en/DOM/event , but you can just not call it...


Shouldn't

if maxwords
   preventDefault
else
   return true

do the trick ?