# Submit form disappears on second call

**URL:** <https://www.ruby-forum.com/t/submit-form-disappears-on-second-call/86682>\
**Category:** Rails\
**Created:** [February 24, 2007, 1:43pm UTC](https://www.ruby-forum.com/t/submit-form-disappears-on-second-call/86682 "2007-02-24T13:43:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jspencer78](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f14d63/32.png) [@jspencer78](https://www.ruby-forum.com/u/jspencer78)\
**Post date:** [February 24, 2007, 1:43pm UTC](https://www.ruby-forum.com/t/submit-form-disappears-on-second-call/86682/1 "2007-02-24T13:43:39Z")

</div>

Hello,

I seem to be having a strange problem. I have a form\_remote\_tag which i  
submit using a javascript call:

if(document.forms[‘myform’].onsubmit()) {  
document.forms[‘myform’].submit(); }

This works great the first time the call is made - however the second  
time it doesn’t seem to work - the form seems to have disappeared and  
have no properties. I then need to refresh the page and it work again,  
then doesn’t work on the second attempt, again…

Any ideas?

Do i have to reload the page after using ajax to submit a form, in order  
to re-use the form?

Thanks for your time

---

<div class="post-metadata">

**Author:** ![jspencer78](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f14d63/32.png) [@jspencer78](https://www.ruby-forum.com/u/jspencer78)\
**Post date:** [February 24, 2007, 4:10pm UTC](https://www.ruby-forum.com/t/submit-form-disappears-on-second-call/86682/2 "2007-02-24T16:10:38Z")

</div>

James, sounds like you’re your :update is writing over your form

look at the partial you’re rendering, and the contents, and what div  
your rendering too - likely you’re rendering to an ID outside the  
form\_tag, with a partial that doesn’t contain the form\_tag.

Jodi

On Feb 24, 7:43 am, James S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![jspencer78](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f14d63/32.png) [@jspencer78](https://www.ruby-forum.com/u/jspencer78)\
**Post date:** [February 24, 2007, 4:45pm UTC](https://www.ruby-forum.com/t/submit-form-disappears-on-second-call/86682/3 "2007-02-24T16:45:45Z")

</div>

James - on second thought it might be the opposite ( you’re rendering  
the form\_tag twice )

but your best bet, sort of a teach a man to fish, is to pickup  
[1]firebug - you’ll sleep better.

Jodi  
[1] [https://addons.mozilla.org/firefox/1843/](https://addons.mozilla.org/firefox/1843/)

---

<div class="post-metadata">

**Author:** ![jspencer78](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f14d63/32.png) [@jspencer78](https://www.ruby-forum.com/u/jspencer78)\
**Post date:** [February 26, 2007, 5:44pm UTC](https://www.ruby-forum.com/t/submit-form-disappears-on-second-call/86682/4 "2007-02-26T17:44:22Z")

</div>

Hey James - I suggest that it’s the first submit that’s causing the  
problem (symptom) you’re seeing, when you try to submit it the second  
time.

Follow the logic carefully  
#1. what is the ID that your form result is rendering to? (:update  
=\> ‘id’)  
#2. what partial is being rendered by your controller? What is  
inside this partial?  
#3. what is currently inside that ID? (on the first render)

I suggest that one of 2 things is happening:  
A. the partial being rendered by the controller (in #2) is rendering  
a second form - if this form is inside the current form, or has the  
same ID then the Second Form Submit will fail to work  
B. the partial being rendered is not rendering the Form Tag - and so  
when you click to submit, the form cannot be found.

this will take some investigation on your part. But if you are careful  
you should be able to find out the confusion - and learn a valuable  
lesson on the way.

Jodi  
On Feb 24, 5:35 pm, James S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![jspencer78](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f14d63/32.png) [@jspencer78](https://www.ruby-forum.com/u/jspencer78)\
**Post date:** [February 24, 2007, 11:35pm UTC](https://www.ruby-forum.com/t/submit-form-disappears-on-second-call/86682/5 "2007-02-24T23:35:56Z")

</div>

> but your best bet, sort of a teach a man to fish, is to pickup  
> [1]firebug - you’ll sleep better.
> 
> Jodi  
> [1] [https://addons.mozilla.org/firefox/1843/](https://addons.mozilla.org/firefox/1843/)

Thanks for this, this seems like a great tool.

When i submit the form on the second time i am getting errors in the  
console.  
The first error is as follows:

this.element has no properties  
(no name)(undefined)prototype.js (line 265)  
\_each(function())prototype.js (line 456)  
each(function())prototype.js (line 261)  
collect(function())prototype.js (line 293)  
invoke(“loop”)prototype.js (line 349)  
loop()effects.js (line 239)  
bind()prototype.js (line 48)  
[Break on this error] if(this.element.getStyle(‘display’)==‘none’) {  
this.cancel(); return; }

and then the console is repeatedly throwing the following error:

this.element has no properties  
[Break on this error] this.element.setStyle({backgroundColor:  
$R(0,2).inject(‘#’,function(m,v,i){

and so it keeps going repeatedly throwing the latter error…

So from this i gather that it cannot find the form element… but then  
i’m not sure how i can read further into this and solve my problem, any  
ideas?

---

<div class="post-metadata">

**Author:** ![jspencer78](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f14d63/32.png) [@jspencer78](https://www.ruby-forum.com/u/jspencer78)\
**Post date:** [February 26, 2007, 9:09pm UTC](https://www.ruby-forum.com/t/submit-form-disappears-on-second-call/86682/6 "2007-02-26T21:09:52Z")

</div>

Finally, i have discovered my wrongs…

I was using effects.js in my rjs file to highlight the form after it had  
been submitted, and this was causing the form to effectively disappear.

Why it took me so long to figure out i will never know…

Thanks for your help on this, firebug is a great tool.
