I'm offering users the ability to type weblog posts into a form and
post them. They type the text into a TEXTAREA which is on a form. The
form, when submitted, hits a PHP script. Before it is submitted, while
they are typing, I'm trying to offer them some common word processing
functions.
I want to implement unlimited undo and redo for the textarea. I've set
the textarea to onChange="addTo ArrayOfPastWork ()";
My undo button gives me "undefined" , but I suppose I can fix that with
a check on the index. My redo button seems to work.
Here is my question:
Currently I'm implementing currentFormInde xValue as a global variable,
but really I want it to be a static variable in a function that
handles both the undo and redo. Does Javascript allow static variables?
I checked here: http://developer.irt.org/script/vfaq.htm
but it didn't mention static variables.
// 12-04-04 - our form functions, especially McFormsPrintNow ,
will output text boxes and textareas
// that call addToArrayOfPas tWork() whenever anything changes.
Then elementsAdminSh owFormattingBut tons
// contains an undo and a redo button that lets users step
through the array and bring back
// past iterations of work.
arrayOfPastForm Work = new Array();
currentFormInde xValue = 0;
function undoFormWork(my Field) {
currentFormInde xValue = currentFormInde xValue - 1;
myField.value =
arrayOfPastForm Work[currentFormInde xValue];
}
function redoFormWork(my Field) {
currentFormInde xValue = currentFormInde xValue + 1;
myField.value =
arrayOfPastForm Work[currentFormInde xValue];
}
function addToArrayOfPas tWork(myField) {
var newValue = myField.value;
arrayOfPastForm Work.push(newVa lue);
}