L
lkrubner
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="addToArrayOfPastWork()";
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 currentFormIndexValue 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 addToArrayOfPastWork() whenever anything changes.
Then elementsAdminShowFormattingButtons
// contains an undo and a redo button that lets users step
through the array and bring back
// past iterations of work.
arrayOfPastFormWork = new Array();
currentFormIndexValue = 0;
function undoFormWork(myField) {
currentFormIndexValue = currentFormIndexValue - 1;
myField.value =
arrayOfPastFormWork[currentFormIndexValue];
}
function redoFormWork(myField) {
currentFormIndexValue = currentFormIndexValue + 1;
myField.value =
arrayOfPastFormWork[currentFormIndexValue];
}
function addToArrayOfPastWork(myField) {
var newValue = myField.value;
arrayOfPastFormWork.push(newValue);
}
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="addToArrayOfPastWork()";
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 currentFormIndexValue 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 addToArrayOfPastWork() whenever anything changes.
Then elementsAdminShowFormattingButtons
// contains an undo and a redo button that lets users step
through the array and bring back
// past iterations of work.
arrayOfPastFormWork = new Array();
currentFormIndexValue = 0;
function undoFormWork(myField) {
currentFormIndexValue = currentFormIndexValue - 1;
myField.value =
arrayOfPastFormWork[currentFormIndexValue];
}
function redoFormWork(myField) {
currentFormIndexValue = currentFormIndexValue + 1;
myField.value =
arrayOfPastFormWork[currentFormIndexValue];
}
function addToArrayOfPastWork(myField) {
var newValue = myField.value;
arrayOfPastFormWork.push(newValue);
}