# Adding some more javascript to run

**URL:** <https://www.ruby-forum.com/t/adding-some-more-javascript-to-run/128979>\
**Category:** Rails\
**Created:** [February 13, 2008, 7:24am UTC](https://www.ruby-forum.com/t/adding-some-more-javascript-to-run/128979 "2008-02-13T07:24:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 13, 2008, 7:24am UTC](https://www.ruby-forum.com/t/adding-some-more-javascript-to-run/128979/1 "2008-02-13T07:24:13Z")

</div>

Hi,

I have a form where I’m adding multiple items. So I have an “Add New  
Item” link to the page. Here’s how I define it in the controller’s  
helper …

```
    def add_item_link(name)
            link_to_function name do |page|

```

page.insert\_html :bottom, :ec\_line\_items, :partial =\>  
“ec\_line\_item”, :object =\> EcLineItem.new  
end  
end

The link is invoked on the page like so:

\<%= add\_item\_link “Add an item” %\>

My question is, let’s say I want an additional javascript function,  
“myFunc()” to run after the above HTML has been inserted. How do I  
modify the helper function above to execute “myFunc()” after it has  
done its thing?

Thanks, - Dave

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 13, 2008, 8:06am UTC](https://www.ruby-forum.com/t/adding-some-more-javascript-to-run/128979/2 "2008-02-13T08:06:34Z")

</div>

Try this:

def add\_item\_link(name)  
link\_to\_function name do |page|  
page.insert\_html :bottom, :ec\_line\_items, :partial =\>  
“ec\_line\_item”, :object =\> EcLineItem.new  
page \<\< “myFunc();”  
end  
end
