Created
October 7, 2009 12:15
-
-
Save overture8/204001 to your computer and use it in GitHub Desktop.
Unobtrusively observe a form with prototype
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
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