# Form\_remote\_tag :onsubmit not working

**URL:** <https://www.ruby-forum.com/t/form-remote-tag-onsubmit-not-working/116218>\
**Category:** Rails\
**Created:** [October 3, 2007, 4:38pm UTC](https://www.ruby-forum.com/t/form-remote-tag-onsubmit-not-working/116218 "2007-10-03T16:38:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![shishir\_s](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f07891/32.png) [@shishir\_s](https://www.ruby-forum.com/u/shishir_s)\
**Post date:** [October 3, 2007, 4:38pm UTC](https://www.ruby-forum.com/t/form-remote-tag-onsubmit-not-working/116218/1 "2007-10-03T16:38:48Z")

</div>

Hi,

Has anyone successfully implemented the :onsubmit option for  
form\_remote\_tag. It doesn’t seem to work for me. Is there any specific  
version of rails which is required for the same.

Here’s my piece of code.

\<%= form\_remote\_tag :update =\> ‘’, :url =\> { :action =\> ‘’}, :onsubmit  
=\> “set\_tojid()”, :after =\> “clearinput()” %\>  
\<%= text\_field\_tag :newmessage, nil, {:style =\> “width:  
100%”, :maxlength =\> “1000”,:autocomplete =\> “off”} %\>  
\<%= hidden\_field\_tag :send\_to, value = ‘’ %\>  
\<%= end\_form\_tag %\>

Anything buggy here??

TIA  
~Shishir

---

<div class="post-metadata">

**Author:** ![shishir\_s](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f07891/32.png) [@shishir\_s](https://www.ruby-forum.com/u/shishir_s)\
**Post date:** [October 3, 2007, 4:55pm UTC](https://www.ruby-forum.com/t/form-remote-tag-onsubmit-not-working/116218/2 "2007-10-03T16:55:48Z")

</div>

On 10/3/07, Shishir S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> function set\_tojid(){  
> Anything buggy here??  
> Lots.

1. You can’t use :onsubmit, because form\_remote\_tag generates an  
onsubmit attribute. You should use :before instead, which will place  
your code in the onsubmit event before the Ajax call.

2. Why are you using :update without an id? If your view is doing RJS,  
you should leave :update off, which generates Ajax.Request instead of  
Ajax.Updater.

3. Using the non-block form is deprecated.

Try this:

\<% form\_remote\_tag :url =\> { :action =\> ‘’},  
:before =\> “set\_tojid()”, :after =\> “clearinput()” do %\>

```
...blah blah

```

\<% end %\>

---

<div class="post-metadata">

**Author:** ![shishir\_s](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f07891/32.png) [@shishir\_s](https://www.ruby-forum.com/u/shishir_s)\
**Post date:** [October 3, 2007, 5:16pm UTC](https://www.ruby-forum.com/t/form-remote-tag-onsubmit-not-working/116218/3 "2007-10-03T17:16:20Z")

</div>

Thanks a lot Bob for cleaning the code. I was actually wary of  
using :before as a substitute of :onsubmit. Anyways, I need one more  
help. I am actually trying to update the value of one of my hidden  
parameters in the form, before submitting like this. Again it seems  
i’ve hit a road block.

\<%= form\_remote\_tag :name =\> ‘minput’, :url =\> { :action =\>  
‘’}, :before =\> “set\_tojid()”, :after =\> “clearinput()” %\>  
\<%= text\_field\_tag :newmessage, nil, {:style =\> “width:  
100%”, :maxlength =\> “1000”,:autocomplete =\> “off”} %\>  
\<%= hidden\_field\_tag :send\_to, value = ‘oldvalue’ %\>  
\<%= end %\>

I have checked the parameters in the post , and the :send\_to parameter  
still hold the oldvalue.

☹

~Shishir

---

<div class="post-metadata">

**Author:** ![shishir\_s](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f07891/32.png) [@shishir\_s](https://www.ruby-forum.com/u/shishir_s)\
**Post date:** [October 3, 2007, 5:22pm UTC](https://www.ruby-forum.com/t/form-remote-tag-onsubmit-not-working/116218/4 "2007-10-03T17:22:47Z")

</div>

On 3 Oct 2007, at 16:15, Shishir S. wrote:

> Thanks a lot Bob for cleaning the code. I was actually wary of  
> using :before as a substitute of :onsubmit. Anyways, I need one more  
> help. I am actually trying to update the value of one of my hidden  
> parameters in the form, before submitting like this. Again it seems  
> i’ve hit a road block.

I’d recommend using firebug’s javascript debugger to step through  
this and see exactly what’s happening

Fred

---

<div class="post-metadata">

**Author:** ![shishir\_s](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f07891/32.png) [@shishir\_s](https://www.ruby-forum.com/u/shishir_s)\
**Post date:** [October 3, 2007, 9:04pm UTC](https://www.ruby-forum.com/t/form-remote-tag-onsubmit-not-working/116218/5 "2007-10-03T21:04:41Z")

</div>

Thanks Fred, I almost forgot that feature of firebug !!

On Oct 3, 8:20 pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
