# JS error when adding/removing items on a form

**URL:** <https://www.ruby-forum.com/t/js-error-when-adding-removing-items-on-a-form/127825>\
**Category:** Rails\
**Created:** [February 1, 2008, 5:11pm UTC](https://www.ruby-forum.com/t/js-error-when-adding-removing-items-on-a-form/127825 "2008-02-01T17:11:09Z")\
**Posts on this page:** 3\
**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 1, 2008, 5:11pm UTC](https://www.ruby-forum.com/t/js-error-when-adding-removing-items-on-a-form/127825/1 "2008-02-01T17:11:09Z")

</div>

Hi,

I’m getting a Javascript error using tried and true RailsCast code!  
I’m submitting a single form for one object (ec\_order), which has many  
of another object (ec\_line\_item) within it. I have links to add and  
remove items in the form. Here is the view:

\<% form\_for :ec\_order, :url =\> ‘summary’ do |f| %\>

| Item | |
| 

| 
 \<%= render :partial =\> 'ec\_line\_item', :collection =\> @ec\_order.ec\_line\_items %\> 
 \<%= add\_prescription\_link "Add a prescription" %\> |

 |
| \<%= submit\_tag("Submit Form") %\> |

\<% end %\>

and here is the partial

 \<% fields\_for "ec\_order[ec\_line\_item\_attributes][]", ec\_line\_item do |ec\_line\_item\_form| %\> 

| \<%= ec\_line\_item\_form.text\_field :prescription\_number %\> | \<%= ec\_line\_item\_form.text\_field :description %\> | \<%= link\_to\_function "remove", "this.up('.ec\_line\_item').remove()" %\> |
| Prescription Number | Description | |

 \<% end %\>

When I click on the “remove” link I get the JS error  
“this.up(”.ec\_line\_item") has no properties". Any ideas what I’m  
doing wrong? - 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 1, 2008, 5:36pm UTC](https://www.ruby-forum.com/t/js-error-when-adding-removing-items-on-a-form/127825/2 "2008-02-01T17:36:07Z")

</div>

I suspect that the problem is that up is a method on the prototype-  
extended Element ‘class’. The examples in the api suggest this – $  
(‘some\_dom\_id’).up() – the dollar-sign function extends the object as  
required.

Have you tried something like $(this).up(".ec\_line\_item").remove()

On Feb 1, 11:10 am, “removed\_email\_address@domain.invalid”

---

<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 1, 2008, 8:44pm UTC](https://www.ruby-forum.com/t/js-error-when-adding-removing-items-on-a-form/127825/3 "2008-02-01T20:44:40Z")

</div>

I tried this as well and got the error “$(this).up(”.ec\_line\_item")  
has no properties"

Thanks though, - Dave
