5

When I have an input field with a certain value in it, and some JavaScript changes its value, I used to be able to click into the field and hit Ctrl-Z in order to get the old value back.

It seems it doesn't work anymore, is that a recent update of the browsers? I am doing something wrong? Is there a way to make it work again?

setTimeout(function () {
  document.getElementById("name").value = ""
}, 2000);
<input type="text" id="name" value="Sylvain" />
sylbru
  • 1,461
  • 1
  • 11
  • 19
  • I found that Chromium correctly undoes the change. At least for restoring past user input actions – tschoppi Apr 10 '19 at 08:02
  • @tschoppi I think you misread my question (unless I misread your comment), I'm only talking about "programmatic" changes to the text field, not user input actions. – sylbru Apr 11 '19 at 15:49
  • What I meant was: Input -> some change (like`replace`) -> More input. Only Chrome correctly handles Ctrl-Z. I found that the Mozilla and MS browsers do not go back past the change. I realize that is not quite exactly your case, and also have no solution to offer. Hence the comment and not an answer. – tschoppi Apr 12 '19 at 04:41
  • Oh ok I get it, thanks for the input (haha) then. – sylbru Apr 12 '19 at 10:19
  • 1
    Answered here: [HTML Input - Undo history lost when setting input value programmatically](https://stackoverflow.com/questions/69503315/html-input-undo-history-lost-when-setting-input-value-programmatically) – Spectric Oct 09 '21 at 21:27
  • Does this answer your question? [Is it possible to edit a text input with javascript and add to the Undo stack?](https://stackoverflow.com/questions/27027833/is-it-possible-to-edit-a-text-input-with-javascript-and-add-to-the-undo-stack) – fregante Apr 25 '23 at 18:18

0 Answers0