This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes Trigger Undo from Javascript? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Trigger Undo from Javascript?" Watch "Trigger Undo from Javascript?" New topic
Author

Trigger Undo from Javascript?

Bert Evans
Greenhorn

Joined: Jun 30, 2005
Posts: 11
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
something like this I believe:

Eric
Ailsa Cape
Ranch Hand

Joined: Aug 10, 2005
Posts: 92
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
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

Joined: Aug 10, 2005
Posts: 92
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
 
Consider Paul's rocket mass heater.
 
subject: Trigger Undo from Javascript?
 
Similar Threads
maintain action history of drag and drop in jtree
UndoManager Help
How can I trigger javascript function before submit struts 2
Textbox value change event
Open JSP page in new tab(browser) from request from servlet