# Inserted html using javascript function

**URL:** <https://www.ruby-forum.com/t/inserted-html-using-javascript-function/188424>\
**Category:** Rails\
**Created:** [May 11, 2010, 7:20pm UTC](https://www.ruby-forum.com/t/inserted-html-using-javascript-function/188424 "2010-05-11T19:20:18Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mlle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/eada6e/32.png) [@Mlle](https://www.ruby-forum.com/u/Mlle)\
**Post date:** [May 11, 2010, 7:20pm UTC](https://www.ruby-forum.com/t/inserted-html-using-javascript-function/188424/1 "2010-05-11T19:20:18Z")

</div>

I’m using a javascript function to insert html code into my page  
(following the Railscast on nested models)

The function that inserts the javascript is this:

function add\_result(link, association, content) {

var new\_id = new Date().getTime();  
var regexp = new RegExp(“new\_” + association, “g”);  
var linkrow = $(link).up(“tr”);

linkrow.insert({  
after: content.replace(regexp, new\_id) });  
}

And this is the html.erb that is inserted:

\<% for c in @picture\_fields %\>

```
<% if c == "intervention" %>
  <tr class="pictureclass">
  <td class="name"><%=t 'form.results.picture.'+c%></td>
  <td><%= f.radio_button c,

```

t(‘form.results.picture.interventionoptions.option1’)%\>\<%=t  
‘form.results.picture.interventionoptions.option1’%\>\<%= f.radio\_button  
c, t(‘form.results.picture.interventionoptions.option2’)%\>\<%=t  
‘form.results.picture.interventionoptions.option2’%\>\<%= f.radio\_button  
c, t(‘form.results.picture.interventionoptions.option3’)%\>\<%=t  
‘form.results.picture.interventionoptions.option3’%\>

  

```
 <% elsif c == "couchetype" %>
  <tr class="pictureclass">
  <td class="name"><%=t 'form.results.picture.'+c%></td>
  <td><%= f.text_field :selected_couchetypes, :readonly=>true %></

```

td\>

\<%=  
link\_to( image\_tag(‘more.png’, :border=\>0,  
:id=\>“new\_results\_pictures\_results\_pictures\_couchetype”),  
{:controller=\>“thesaurus”, :action=\>“list”,  
:id=\>“new\_results\_pictures\_results\_pictures\_couchetype”},  
{ :popup=\>[‘thesaurus’,  
‘height=800,width=750,location=no,scrollbars=yes’]}) %\>  
  

```
 <%else %>
   <tr class="pictureclass"><td></td><td ></td></tr>
   <tr class="pictureclass">
   <td class="name"><%=t 'form.results.picture.'+c%></td>
   <td><%= f.text_field c, :class=>"number"%></td>
   </tr>

 <% end %>

```

\<% end %\>

\<%=  
f.hidden\_field :\_destroy %\>\<%= link\_to\_function  
t(‘form.results.picture.destroy’), “remove\_fields(this,  
‘.pictureclass’)”%\>

When the html is inserted, there is a size=“30” attribute for the text  
input field:

But I have no idea how it got there. Any ideas?
