views:

25

answers:

1

I'm sure this is a basic question... I have a nested form where the nested object contains a text field. There is a link_to_function in the form that calls some javascript. I want to pass the javascript function the value of a hidden field in the form (image_type_id).

Can I reference this with some ruby or does this need javascript?

A: 

Pass this (or this.parent, depending on where your link is on the form) and use jQuery on the Javascript side to get the hidden value.

Júlio Santos
thanks. what is "this"? A hash of field names and values?
nktokyo
@Julio Santos: Why jQuery? It can be anything right? And I am guessing this most certainly would be Prototype, which is the default with Rails?
Swanand
@nktokyo"this" is, well, that :) Picture the following:<form onsubmit="doSomething(this)">...</form>When the javascript function doSomething(form) is called, inside it you can refer to the form as a DOM element.@SwanandSure, jQuery is just what I'm used to, even with Rails. But you can use anything.
Júlio Santos
@nktokyo For instance, if inside the function you did (this is jQuery) $(form).hide(), this would hide the form. That's the use of "this".
Júlio Santos
Thanks, I was able to figure it out from your hint
nktokyo