Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Trigger Undo from Javascript?

 
Bert Evans
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a way to trigger the undo that occurs when a user types Ctrl-Z (in IE, I don't know about other browsers) in a text box from Javascript?

Bert Evans
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
something like this I believe:

Eric
 
Ailsa Cape
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Eric,

After I test the "document.execCommand('undo', false, null)" method, I find it works well in text-oriented HTML elements when you want to roll back what a user has done. Now I am eager to know how to undo the user's operation using Javascript. For example, in a web page which is used for writing questions for a quiz, a user will do from scratch when he logged on and he might take the following steps:

1) Press a select element to choose the nubmer of answers for the first question.
2) Create a table on the fly whose rows are equal to the previous selected number plus 1.
3)Fill in the question and its answers.
4)Generate a "Next" button on the fly automatically when he is about to input the last answer.
5)Press the "Next" button to write the second question.

How can I afford a list A to let the user undo the above operation and a list B redo these operation step by step? In other words, how can I implement this functionality using Javascript just like what we do in Microsoft's Excel?

Thanks in advance!
Regards, Ailsa Cape
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You would have to code the functionality yourself. Build an array/object that contains the steps and when they undo, you look at your array, find the elements that need to be removed.

The browser does not understand changes made to the UI via JavaScript.

Eric
 
Ailsa Cape
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Eric,

Thank you for your quick response! Can you introduce some material or web links which thoroughly discuss the subject to me?

Best Regars, Ailsa Cape
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic