# Submit Form with AJAX on javascript event

**URL:** <https://www.ruby-forum.com/t/submit-form-with-ajax-on-javascript-event/117448>\
**Category:** Rails\
**Created:** [October 17, 2007, 12:25am UTC](https://www.ruby-forum.com/t/submit-form-with-ajax-on-javascript-event/117448 "2007-10-17T00:25:20Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![chrismalek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/6de8d8/32.png) [@chrismalek](https://www.ruby-forum.com/u/chrismalek)\
**Post date:** [October 17, 2007, 12:25am UTC](https://www.ruby-forum.com/t/submit-form-with-ajax-on-javascript-event/117448/1 "2007-10-17T00:25:20Z")

</div>

I’m new to rjs and ajax…doing the example in RJS Templates for  
rails.

I’d like to submit the form onChange…but my onChange code doesn’t  
work as expected. I get the js code in the browser window…instead of  
my updated page.

It does still work when I press the submit button though.

My form code:

\<%= form\_remote\_tag :url =\> {:action =\> ‘log’}, :html =\> { :id =\>  
‘thought-form’} %\>  
\<%= text\_field\_tag ‘thought’, nil, {:size =\> 40, :onChange =\>  
‘this.form.submit()’} %\>  
\<%= submit\_to\_remote ‘Log thought’, ‘Check’ %\>

This is what I see in the browser.

try {  
new Insertion.Top(“thoughts”, “

\n\ta random thought\n

”);  
new Effect.Highlight(“thoughts”,{});  
Form.reset(“thought-form”);  
} catch (e) { alert(‘RJS error:\n\n’ + e.toString()); alert(‘new  
Insertion.Top(“thoughts”, “

\n\tchris.ca EXIST\n

”);\nnew  
Effect.Highlight(“thoughts”,{});\nForm.reset(“thought-form”);’);  
throw e }

Any Ideas?
