# Onsubmit continues after return false

**URL:** <https://www.ruby-forum.com/t/onsubmit-continues-after-return-false/119807>\
**Category:** Rails\
**Created:** [November 10, 2007, 7:32pm UTC](https://www.ruby-forum.com/t/onsubmit-continues-after-return-false/119807 "2007-11-10T19:32:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![miked](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed655f/32.png) [@miked](https://www.ruby-forum.com/u/miked)\
**Post date:** [November 10, 2007, 7:32pm UTC](https://www.ruby-forum.com/t/onsubmit-continues-after-return-false/119807/1 "2007-11-10T19:32:00Z")

</div>

Hi, I have something really weird going on.

In this form header:

\<% form\_for(:task,:url =\> tasks\_path, :html =\> { :onsubmit =\>  
‘validate\_task();’, :id =\> “new\_task” }) do |f| %\>

I call “validate\_task” to validate some of the form inputs. The  
javascript returns false when I don’t fill in the task name. Simple,  
right. What’s weird is that the form submit continues even though the  
javascript returns false. Why is this?

I’ve tried to work around this. If I have the onsubmit return false,  
the form doesn’t get submitted. But when I have a function call return  
false, the form still submits through. The validate function is in  
application.js.

Any help you can give would be greatly appreciated!

Mike

---

<div class="post-metadata">

**Author:** ![miked](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed655f/32.png) [@miked](https://www.ruby-forum.com/u/miked)\
**Post date:** [November 10, 2007, 7:55pm UTC](https://www.ruby-forum.com/t/onsubmit-continues-after-return-false/119807/2 "2007-11-10T19:55:58Z")

</div>

On 10 Nov 2007, at 18:32, Mike D. wrote:

> right. What’s weird is that the form submit continues even though the  
> javascript returns false. Why is this?

You actually have to say return foo - this isn’t like ruby, ie your  
onsubmit should be ‘return validate\_task();’

Fred
