simulate backspace key on text input field

html, javascript

Solution

Alright here you go: http://jsfiddle.net/dan_barzilay/WWAh7/2/

The get caret function is used to know where to delete the character, if you need more explaining comment. The reset cursor function is used to restore the caret position after the backspacing.

**it's using jquery but you can change it to normal js in secounds

Problem

Can someone provide a good example to simulate the backspace key on a `<INPUT>` text field? I need this for a virtual keyboard done in HTML5 and it only needs to work in Webkit browsers. Notes: - `createEvent`/`initTextEvent`/`dispatchEvent` with charcode 8 (backspace) is being ignored (that seems to work only for printable characters) - changing manually the `value` using `substr()` sort of works, but this way the caret moves to the end of the input field (and I want to be able to delete characters in the middle of the input field, just like when using a normal keyboard).

Original source

Related problems