Calling all Javascript Masters

I’m using ajax more and more in my apps, and there is one particular
piece of technology that I’m missing that would really make things
cleaner and smoother.

In a normal form, there is a submit button that delivers all of the
values of the form objects to the called method. Same is true for an
ajax form. Quite often with ajax though, you want to have other
buttons or links on the page that change the form in some way, often
dependent on the value of one or more form elements. Unfortunately, a
regular “LinkToRemote” does not provide any useful form related params
to the called method.

So far I’ve been dealing with this nuisance by using observers, but that
can be slow and probably adds some unnecessary load on the server, and
it’s ugly in the code.

I’ve discovered that if I include something like :foo => ‘bar’ in the
url params for a LinkToRemote, then :foo => ‘bar’ gets added to the
params sent to the called method.

What can I put in place of ‘bar’ above in the LinkToRemote call that
will send the value of a particular form element in the params instead
of ‘bar’?

I’ve tried a few things, but alas, I only played with javascript for a
short time before I found out about Rails. When it comes to JavaScript,
I am the weakest link.

thanks for the help,
jp

Phlip wrote:

Jeff P. wrote:

:with => ‘Form.serialize(“my_form”)’, right?


Phlip
http://c2.com/cgi/wiki?ZeekLand ← NOT a blog!!

What Phlip suggests would send all of the form parameters up as
parameters on the AJAX request. If you just want to do one, something
like:

:with => “"param_name=" + $F(‘form_elem_name’)”

should work well, assuming that form_elem_name is a text field. $F(‘x’)
in Prototype will give you the value of x if x is a <INPUT
type=“text”…>.

Equally valid should be:

:with => “"param_name=" + this.form.form_elem_name.value”

The thing to realize about the :with parameter is the string it points
to needs to be valid, evaluatable (not a word I know :]) Javascript.

Hope this makes sense.

Wes

Wes G. wrote:

Phlip wrote:

:with => ““param_name=” + this.form.form_elem_name.value”

Wes

Thanks Wes and Philip. Wish I had asked this question a few projects
ago!

jp

Jeff P. wrote:

In a normal form, there is a submit button that delivers all of the
values of the form objects to the called method. Same is true for an
ajax form. Quite often with ajax though, you want to have other
buttons or links on the page that change the form in some way, often
dependent on the value of one or more form elements. Unfortunately, a
regular “LinkToRemote” does not provide any useful form related params
to the called method.

:with => ‘Form.serialize(“my_form”)’, right?


Phlip
http://c2.com/cgi/wiki?ZeekLand ← NOT a blog!!