# Observe\_form without ajax?

**URL:** <https://www.ruby-forum.com/t/observe-form-without-ajax/55558>\
**Category:** Rails\
**Created:** [March 22, 2006, 2:40am UTC](https://www.ruby-forum.com/t/observe-form-without-ajax/55558 "2006-03-22T02:40:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Payton\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/74df32/32.png) [@Payton\_S](https://www.ruby-forum.com/u/Payton_S)\
**Post date:** [March 22, 2006, 2:40am UTC](https://www.ruby-forum.com/t/observe-form-without-ajax/55558/1 "2006-03-22T02:40:47Z")

</div>

This betrays my lack of javascript knowledge, but is it possible to  
watch a whole form for changes and activate some javascript when those  
changes occur without any remote request?

That is, I want to do exactly what observe\_form does, but without the  
ajax call actually happening. I realize I could use the form\_tag  
:onchange parameter, but that seems to be incapable of doing things like  
updating a DOM element style.

Currently I just put my javascript in :complete and have the ajax render  
:nothing =\> true, but that’s a hack and uses unnecessary bandwidth.

-Payton

---

<div class="post-metadata">

**Author:** ![Payton\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/74df32/32.png) [@Payton\_S](https://www.ruby-forum.com/u/Payton_S)\
**Post date:** [March 22, 2006, 3:11am UTC](https://www.ruby-forum.com/t/observe-form-without-ajax/55558/2 "2006-03-22T03:11:45Z")

</div>

Although in danger of answering my own question, I just discovered how  
to work prototype’s Form.Observer. It appears to do the trick, although  
it means I have to encapsulate my javascript in a separate function in  
order to use the callback feature.

Sorry to trouble you all.

-Payton

---

<div class="post-metadata">

**Author:** ![Payton\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/74df32/32.png) [@Payton\_S](https://www.ruby-forum.com/u/Payton_S)\
**Post date:** [March 22, 2006, 2:36pm UTC](https://www.ruby-forum.com/t/observe-form-without-ajax/55558/3 "2006-03-22T14:36:41Z")

</div>

If you are running EdgeRails or the new Rails 1.1.0 RC1 release  
candidate then you can do this in your view:

\<%= observe\_form ‘form\_id’, :frequency =\> 2, :function =\> “alert  
(‘Form changed’)” %\>

The :function option can be any javascript that you want to execute.

-Jonathan
