# Onsubmit for remote\_form\_for not working properly

**URL:** <https://www.ruby-forum.com/t/onsubmit-for-remote-form-for-not-working-properly/162465>\
**Category:** Rails\
**Created:** [March 10, 2009, 6:20am UTC](https://www.ruby-forum.com/t/onsubmit-for-remote-form-for-not-working-properly/162465 "2009-03-10T06:20:28Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![salil](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c89c15/32.png) [@salil](https://www.ruby-forum.com/u/salil)\
**Post date:** [March 10, 2009, 6:20am UTC](https://www.ruby-forum.com/t/onsubmit-for-remote-form-for-not-working-properly/162465/1 "2009-03-10T06:20:28Z")

</div>

I want to use onsubmit for a form validation using javascript on  
remote\_form\_for

for this i am doing something like this

\<% remote\_form\_for :timesheet, @timesheet, :url =\>{:action =\>  
‘report\_user’}, :html =\> {:onsubmit=\>“return ValidateDate();” } do |f|  
%\>

```
// Form elements here

```

\<% end %\>

but it not works well. if condition return false then my form is not get  
submitted this is exactly what i want but when it returns true it  
produce something like this o/p on UI.

Element.update(“user\_report”, "\n\n\u003Ctable class=“list  
issues”\u003E\n \u003Cthead\u003E\u003Ctr\u003E\n  
\u003Cth\u003E#\u003C/th\u003E\n

when i delete :html code it works fine.

Regards,  
Salil

---

<div class="post-metadata">

**Author:** ![salil](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c89c15/32.png) [@salil](https://www.ruby-forum.com/u/salil)\
**Post date:** [March 10, 2009, 8:29am UTC](https://www.ruby-forum.com/t/onsubmit-for-remote-form-for-not-working-properly/162465/2 "2009-03-10T08:29:33Z")

</div>

> \<% remote\_form\_for :timesheet, @timesheet, :url =\>{:action =\>  
> ‘report\_user’}, :html =\> {:onsubmit=\>“return ValidateDate();” } do |f|  
> %\>

> I guess this is a JavaScript issue. What about showing us that?

Thanx 4 ur reply

No i am just telling what problem i m facing.  
i just want to know is onsubmit working properly with remote\_form\_for?  
and wheather there is any syntax error in my code above ?

Regards,  
Salil

---

<div class="post-metadata">

**Author:** ![salil](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c89c15/32.png) [@salil](https://www.ruby-forum.com/u/salil)\
**Post date:** [March 10, 2009, 8:17am UTC](https://www.ruby-forum.com/t/onsubmit-for-remote-form-for-not-working-properly/162465/3 "2009-03-10T08:17:01Z")

</div>

On 10 Mar., 06:20, Salil G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> I want to use onsubmit for a form validation using javascript on  
> remote\_form\_for

> but it not works well. if condition return false then my form is not get  
> submitted this is exactly what i want but when it returns true it  
> produce something like this o/p on UI.
> 
> Element.update(“user\_report”, "\n\n\u003Ctable class="list  
> issues"\u003E\n \u003Cthead\u003E\u003Ctr\u003E\n  
> \u003Cth\u003E#\u003C/th\u003E\n

I guess this is a JavaScript issue. What about showing us that?

---

<div class="post-metadata">

**Author:** ![salil](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c89c15/32.png) [@salil](https://www.ruby-forum.com/u/salil)\
**Post date:** [March 17, 2009, 4:02pm UTC](https://www.ruby-forum.com/t/onsubmit-for-remote-form-for-not-working-properly/162465/4 "2009-03-17T16:02:00Z")

</div>

On 10 Mar., 08:29, Salil G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > \<% remote\_form\_for :timesheet, @timesheet, :url =\>{:action =\>  
> > ‘report\_user’}, :html =\> {:onsubmit=\>“return ValidateDate();” } do |f|  
> > %\>  
> > I guess this is a JavaScript issue. What about showing us that?
> 
> Thanx 4 ur reply
> 
> No i am just telling what problem i m facing.  
> i just want to know is onsubmit working properly with remote\_form\_for?  
> and wheather there is any syntax error in my code above ?

No, remote\_form\_for will use the onsubmit event to make the actual  
AJAX request. So I don’t think overriding the onsubmit attribute would  
be a good idea… 🙂

–  
Cheers,  
David K.  
[http://twitter.com/rubyguy](http://twitter.com/rubyguy)

---

<div class="post-metadata">

**Author:** ![salil](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c89c15/32.png) [@salil](https://www.ruby-forum.com/u/salil)\
**Post date:** [March 17, 2009, 5:36pm UTC](https://www.ruby-forum.com/t/onsubmit-for-remote-form-for-not-working-properly/162465/5 "2009-03-17T17:36:45Z")

</div>

On Mar 17, 4:17 pm, Salil G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > No, remote\_form\_for will use the onsubmit event to make the actual  
> > AJAX request. So I don’t think overriding the onsubmit attribute would  
> > be a good idea… 🙂
> 
> thanx @David.  
> Do you know what should do in that case to put javascript form  
> validations?

The ajax helpers can take a :conditions parameter which is a fragment  
of javascript to run to check whether the request should go ahead  
(it’s described in the docs for link\_to\_remote)

Fred

---

<div class="post-metadata">

**Author:** ![salil](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c89c15/32.png) [@salil](https://www.ruby-forum.com/u/salil)\
**Post date:** [March 17, 2009, 5:17pm UTC](https://www.ruby-forum.com/t/onsubmit-for-remote-form-for-not-working-properly/162465/6 "2009-03-17T17:17:01Z")

</div>

> No, remote\_form\_for will use the onsubmit event to make the actual  
> AJAX request. So I don’t think overriding the onsubmit attribute would  
> be a good idea… 🙂

thanx @David.  
Do you know what should do in that case to put javascript form  
validations?

Thanx & Regards  
Salil
