In Chrome, I noticed that undo does not work properly for input element after the contents of the element has been changed programmatically. Although I get different behavio
Chrome doesn't store the field's states, but rather a diff or set of deltas for each undo/redo. It takes less memory, but causes the bug you're dealing with.
You can effectively simulate the user pasting a value into the field by using document.execCommand("insertText", false, "text to insert");
.
For your particular case:
var temp = caller.value;
caller.focus();
document.execCommand("insertText", false, temp.trim());
I found this solution in another SO question, https://stackoverflow.com/a/10345596/1021426