How can I unobtrusively disable submit buttons with Javascript and Prototype?
Posted
by Frew
on Stack Overflow
See other posts from Stack Overflow
or by Frew
Published on 2009-02-23T01:02:34Z
Indexed on
2010/03/20
23:01 UTC
Read the original article
Hit count: 147
JavaScript
|prototype
So I found this recommendation, but I can't quite seem to figure out how.
This is the code I originally started with:
function greySubmits(e) {
var value = e.srcElement.defaultValue;
// This doesn't work, but it needs to
$(e).insert('<input type="hidden" name="commit" value="' + value + '" />');
// This causes IE to not submit at all
$$("input[type='submit']").each(function(v) {v.disabled = true;})
}
// This works fine
Event.observe(window, 'load', function() {
$$("input[type='submit']").each(function(e) {
Event.observe(e, 'click', greySubmits);
});
});
Anyway, I am pretty close, but I can't seem to get any further.
Thanks for any help at all!
Update: Sorry, I guess I wasn't entirely clear. I'd like to disable all of the submit buttons when someone clicks a submit button. But I do need to send along the value of the submit button so the server knows which button I clicked, hence the insert call. (Note: insert does not create a child of the element you call it on.) And then after disabling the submit buttons I need to call the containing form of the submit buttons submit call, as IE will not submit after you disable the button. Does that make sense?
© Stack Overflow or respective owner