secret
Last active

  • Download Gist
form-handler.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
// 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);
});

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.