Prototype Form.Event

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 %>

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:

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


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 C. [email protected]