Submit form and clear value of text field (Rails)
I have a rails form to simply post data and using ajax, reload.
format.js{ render :update do |page|
page.reload
end}
I want to also, clear the value of a textbox inside the form because right now, the textboxes just keep the same value. If they were "hello" and the other was "world", I would click submit, it would run reload
, and keep the same textbox values.
EDIT I'm using the default javascripts 开发者_StackOverflow社区produced by rails. Prototype.js, application.js (etc.)
Try resetting for form like so:
page[:the_form].reset
You can also update a specific text field value:
page[:foo].value = 'Hello!'
If this is an AJAX call, I suspect the right way to clear the form is in your success callback from the ajax call. If you're using ExtJS or jQuery, this should be pretty easy to do, but without letting us know which JS library you use we can't be much more explicit.
精彩评论