Let's look at the form:
HTML Code:
<form autocomplete="off" method="POST" class='form-name'>
<button type="submit" name="name_can_vary">Text Can Vary</button>
</form>
and the relevant scripting code is:
Code javascript:
function change_button(evt) {
evt = evt || window.event;
var targ = evt.target || evt.srcElement;
targ.name_can_vary.innerHTML = "CHANGED - OK";
...
}
You have associated a function with the form onsubmit event, which means that you cannot easily gain access to the button that was used to trigger the event.
Currently your code is retrieving the target that the event takes place on. Since the onsubmit event cannot take place on a button, but only with the form, it is the form that is the target of your onsubmit event.
What this means is, is that the targ variable of your code is just the same as the this keyword, both being the form itself. So you could instead use this to get the element with a submit type:
Code javascript:
this.querySelector('[type="submit"]).innerHTML = "CHANGED - OK";
Bookmarks