-
-
Save nakajima/5e44a2aa8b627a74389b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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