Reset comment form using js or RJS

I have a placeholder 'pre-text' value which is given to a comment form input via the application.js;

Event.observe(window, 'load',

comment_pre_text = "Leave a comment..." var el = $('comment_body') if(el) { el.value = comment_pre_text Event.observe(el, 'focus', function() { if(this.value == comment_pre_text) this.value = ''; }) Event.observe(el, 'blur', function() { if(this.value == '') this.value = comment_pre_text; }) }

} );

However, I've since started using RJS to make submissions through the comment form, and now the pre-text js breaks - it doesn't show the pre-text after a form submission unless I click in and then out of the comment form. This problem could be fixed by turning the comments in the following RJS template in to working code (which I haven't worked out how to do yet);

page.insert_html :bottom, :items_wrapper, :partial => "comment", :object => @comment page[:comment_form].reset # focus on the comment input # focus out of the comment input page.visual_effect :highlight, "comment_#{@comment.id}" flash.discard

Alternatively, I expect this problem could also be fixed by adding another line to the application.js, which I imagine would read something like this (I'm new to js and I can't find a 'reset' equivalent to 'focus' or 'blur' yet - both of which I don't understand fully);

Event.observe(el, 'reset', function() { if(this.value == '') this.value = comment_pre_text; }) }

Any ideas?

Neil ,

   > I can't find a 'reset' equivalent ..

Prototype has a form reset method :   Form.reset('my_form') or   $(my_form').reset()

api doc: Prototype API Documentation | Form.reset (Deprecated URL)

Alain

Alain Ravet wrote:

Neil ,

   > I can't find a 'reset' equivalent ..

Prototype has a form reset method :   Form.reset('my_form') or   $(my_form').reset()

api doc: Prototype API Documentation | Form.reset (Deprecated URL)

Alain

Thanks Alain. I've tried taking the approach that I thought would work, i.e. telling the application.js to watch for when the comment_form is reset (by the RJS) and to do the pre-text when the event occurs;

comment_pre_text = "Leave a comment..." var el = $('comment_body') if(el) { el.value = comment_pre_text Event.observe(el, 'focus', function() { if(this.value == comment_pre_text) this.value = ''; }) Event.observe(el, 'blur', function() { if(this.value == '') this.value = comment_pre_text; }) Event.observe(el.reset(), function() { if(this.value == '') this.value = status_pre_text; }) }

That approach doesn't seem to work. Do you have any ideas on that one? Or do you know if there's an RJS helper for focusing in and out of an input?