here’s the challenge:
1) onLoad, I’m running a function that provides an onChange handler for all form elements because I want something to happen if and only if on the elements is changed. What’s supposed to happen is a button changes from saying “Done” to saying “Cancel”
2) however, the original form contains just a handful of form elements that already have onChange handlers.
3) because my script runs onLoad, it *replaces*appending
4) so I’ve been trying to write the onLoad function so that it does something like “for any element that has an onChange handler, take the previous handler and combine it with this new one”. I can’t figure out how to do this.
4b) It is a possiblity to simply say “for any element that has an onChange handler, just skip” and then I’ll manually add the new, onLoad handler to those elements. But if it’s possible, I’d like a more elegant solution.
Can anyone please help? Here’s my floundering script below:
function DoneCancel(formobj, buttobj1) {
for (i=0; i<formobj.length; i++) {
oldonchange = formobj.elements[i].onchange;
newonchange = function() {buttobj1.value = “Cancel”};
if (oldonchange) allonchange = function() {oldonchange; newonchange;};
else allonchange = function() {newonchange;};
formobj.elements[i].onchange = allonchange;
}
}
?