Skip to content

Instantly share code, notes, and snippets.

@overture8
Created October 7, 2009 12:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save overture8/204001 to your computer and use it in GitHub Desktop.
Save overture8/204001 to your computer and use it in GitHub Desktop.
Unobtrusively observe a form with prototype
var ObserveForm = Class.create({
initialize: function() {
this.form = $('form_id');
this.form.observe('submit', this.submitForm.bindAsEventListener(this));
this.data_area = $('display_area');
},
submitForm: function(event) {
event.stop();
this.form.request({
onSuccess: this.itemCreated.bindAsEventListener(this)
});
},
itemCreated: function(transport) {
this.data_area.insert({top: transport.responseText});
this.form.reset();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment