Skip to content

Instantly share code, notes, and snippets.

@nakajima
Created June 27, 2009 00:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nakajima/5e44a2aa8b627a74389b to your computer and use it in GitHub Desktop.
Save nakajima/5e44a2aa8b627a74389b to your computer and use it in GitHub Desktop.
// A simple event handler for submitting a form via AJAX,
// then closing its containing window.
function submitForm(element) {
// This is a Prototype method for submitting a form
$(element).request({
// This is a callback that will be invoked once the
// request finishes. It just closes the window.
onComplete: function() { window.close(); }
});
// Prevent the form from actually submitting and reloading
// the page:
return false;
}
// Wait until the page has loaded...
$(document).observe('dom:loaded', function() {
// ...then unobtrusively assign the event handler. This
// this prevents the need for the "onclick" attribute in
// your HTML markup.
$('contact').observe('submit', submitForm);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment