Forum: Ruby on Rails Prototype Form.Event

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
27517e2d301a75a98ed458dd466953da?d=identicon&s=25 sexyhalibut (Guest)
on 2007-02-02 01:48
(Received via mailing list)
So, I have a remote form that, upon submission, displays a result and
itself again.  I'd like, though, for it to clear the text field and
set the focus there when it redisplays.  I've been able to get it to
focus the form properly, by setting :complete => "$
('phone_number').focus()".  But, I've not been able to get it to focus
AND clear the fields.  I've tried:


All with no luck.  Any suggestions?

I've included a more complete snippet below...

<% form_remote_tag :url => {:controller => 'phones',
                            :action => 'create'},
                   :update => 'phones',
                   :complete => "$('phone_number').focus();" do %>
  <%= text_field 'phone', 'number', {:size => 12, :value =>
(@phone.number unless @phone.nil?).to_s}  %>
  <%= submit_tag "Add Phone" %>
<% end %>
2da252cc1d2fb3701126171831b50a65?d=identicon&s=25 Dave Coleman (pezdude)
on 2007-02-02 02:06
sexyhalibut wrote:
>   <%= text_field 'phone', 'number', {:size => 12, :value =>
> (@phone.number unless @phone.nil?).to_s}  %>

without seeing the HTML that is generated, the dom id for this tag needs
to be phone_number (id="phone_number") for that to work correctly.

I'm assuming if you have a dom id for this text field, that rails is
generating it as id="phone[number]" ?

Use firefox and get a copy of firebug to help yourself out debugging
javascript issues, the developer toolbar is also really helpful.

web dev toolbar:
27517e2d301a75a98ed458dd466953da?d=identicon&s=25 sexyhalibut (Guest)
on 2007-02-02 03:40
(Received via mailing list)
the dom id is, in fact, phone_number.  it's generating
id="phone_number" name="phone[number]".  i don't have firebug, but i
do have the developer toolbar, and it shows absolutely nothing.

On Feb 1, 8:06 pm, David Coleman <>
27517e2d301a75a98ed458dd466953da?d=identicon&s=25 sexyhalibut (Guest)
on 2007-02-02 17:13
(Received via mailing list)
OK; turns out it wasn't a Javascript error at all.  My view was
filling in the default value, when it shouldn't have been.

The Firebug suggestion really helped out, though, as its HTML
inspector made it way more obvious than just viewing source in

This topic is locked and can not be replied to.