# Ajax insertion into a form

**URL:** <https://www.ruby-forum.com/t/ajax-insertion-into-a-form/100265>\
**Category:** Rails\
**Created:** [February 2, 2006, 10:53am UTC](https://www.ruby-forum.com/t/ajax-insertion-into-a-form/100265 "2006-02-02T10:53:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pierre\_Gambarotto](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e8c25b/32.png) [@Pierre\_Gambarotto](https://www.ruby-forum.com/u/Pierre_Gambarotto)\
**Post date:** [February 2, 2006, 10:53am UTC](https://www.ruby-forum.com/t/ajax-insertion-into-a-form/100265/1 "2006-02-02T10:53:41Z")

</div>

After an ajax insertion in the dom, it seems the browser don’t  
refresh its knowledge of the page.

The source of the page is identical after the insertion, whereas the  
display is correct.

The ajax insertion is used to add an input field. The added fields  
are ignored by the submission of the form.

Isn’t it possible to do that, or maybe there’s a problem in my code ?

The view :

new.rhtml  
\<%= start\_form\_tag :action =\> ‘create’ %\>  
\<%= render\_partial ‘form’ %\>

Telephone

```
<%= link_to_remote("Add a number",
                    :url=>{:action=>'new_tel'},
                     :update =>'telephone', :position=> :after)
 %>
<br/>

```

\<%= text\_field\_tag ‘telephone’ %\>

  
\<%= submit\_tag “Create” %\>  
\<%= end\_form\_tag %\>

The controller :  
def new  
session[:num\_tels]=0  
end

def new\_tel  
@tel\_num=session[:num\_tels]  
@tel\_num=@tel\_num.succ  
session[:num\_tels]=@tel\_num  
render (:text=\>"  
"+@tel\_num.to\_s+’\<input  
id=“telephone”’+@tel\_num.to\_s+’ name=“telephone”+@tel\_num.to\_s  
type=“text” /\>’)  
end

---

<div class="post-metadata">

**Author:** ![Pierre\_Gambarotto](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e8c25b/32.png) [@Pierre\_Gambarotto](https://www.ruby-forum.com/u/Pierre_Gambarotto)\
**Post date:** [February 2, 2006, 11:03am UTC](https://www.ruby-forum.com/t/ajax-insertion-into-a-form/100265/2 "2006-02-02T11:03:10Z")

</div>

You mean that the display of your page changes as expected, but when  
you do a “view source”, the new input field isnt visible in the  
source?

The browser’s “view source” will display the page source as  
downloaded, and not as inferred from the DOM. If you want to view an  
HTML version of the current DOM (say, after your AJAX update), I  
recommend the Aardvark plugin for firefox. It lets you select any  
container on the page (like your form element), and view its source as  
inferred from the DOM.

cheers  
Gerret

---

<div class="post-metadata">

**Author:** ![Pierre\_Gambarotto](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e8c25b/32.png) [@Pierre\_Gambarotto](https://www.ruby-forum.com/u/Pierre_Gambarotto)\
**Post date:** [February 2, 2006, 5:22pm UTC](https://www.ruby-forum.com/t/ajax-insertion-into-a-form/100265/3 "2006-02-02T17:22:05Z")

</div>

Le 2 févr. 06 à 11:01, Gerret A. a écrit :

> 

Thanks, great tool ! And of course the glitch was in my code ^^  
[http://www.karmatics.com/aardvark/](http://www.karmatics.com/aardvark/)

---

<div class="post-metadata">

**Author:** ![Pierre\_Gambarotto](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e8c25b/32.png) [@Pierre\_Gambarotto](https://www.ruby-forum.com/u/Pierre_Gambarotto)\
**Post date:** [February 2, 2006, 7:08pm UTC](https://www.ruby-forum.com/t/ajax-insertion-into-a-form/100265/4 "2006-02-02T19:08:04Z")

</div>

Man, I was sooooo looking foward to this Aardvark plug-in.  
However, it appears it is not compatible with FF 1.5.0.1 (which my FF  
was  
automatically updated with last night).

☹

Oh well, maybe soon???

~damon

---

<div class="post-metadata">

**Author:** ![Pierre\_Gambarotto](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e8c25b/32.png) [@Pierre\_Gambarotto](https://www.ruby-forum.com/u/Pierre_Gambarotto)\
**Post date:** [February 2, 2006, 7:26pm UTC](https://www.ruby-forum.com/t/ajax-insertion-into-a-form/100265/5 "2006-02-02T19:26:13Z")

</div>

Hi Damon,

Here is a great firefox extension for viewing the rendered source.

[http://jennifermadden.com/scripts/ViewRenderedSource.html](http://jennifermadden.com/scripts/ViewRenderedSource.html)

Also if you want to see your ajax requests, it would suggest Julien  
Couvreur’s greasemonkey script at:

[http://blog.monstuff.com/archives/images/XMLHttpRequestDebugging.v1.2.user.js](http://blog.monstuff.com/archives/images/XMLHttpRequestDebugging.v1.2.user.js)

Hope this can help out,  
Eric

Damon H. wrote:

> On 2/2/06, _Pierre Gambarotto_ \<removed\_email\_address@domain.invalid  
> \> The browser’s “view source” will display the page source as
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

–  
Eric G.  
[http://www.ericgoodwin.com](http://www.ericgoodwin.com)
