Accessing form elements

I posted a question earlier but it didn't come out that clear and I have
spent the whole day looking this up. Any help would be much
appreciated.

Here goes round 2:

I have several textareas on the screen (anywhere from 1 - 5). Right now
I have them in a form and am using a submit button to pass the values to
the controller. What I need to do is pass these values to the
controller using links located outside of the actual form. When the
link is click the values from the textareas are passed to the controller
along with a :question parameter. The values of the textareas are saved
into the db and the :question param is used in a query and then the page
is redirected to another page with the result from the query as another
param.

The part I cannot seem to find an answer for is how to pass the values
of the textareas to the controller using link_to(), not link_to_remote.
Or how do you access the textarea values and attach them to :value1 =>
???

I really hope that made more sense.

Thanks,

Chris

It's got to either be javascript or a form submit(and you need
javascript to trigger that from a regular link).

Fred

I initially tried it with a remote_function and used that with an
onunload event but it would only work 50% of the time. I also tried
onclick with the same remote_function but I think the responses were too
long and it would only grab half of it before moving on.

Oh well, I guess I am going to have to say I can't do it the way they
want it.

Thanks anyways,

chris

Sorry I misread your response. How would I trigger the form submit from
a link? That is what I have been looking to do all day and could only
find ajaxy ways of doing it which wouldnt allow me to redirect
afterwards.

onclick="some_form.submit()". At that point you might as well just be
styling the form's submit button to not look like a button.

Fred

So you've got a traditional form generated by form_for, with the
expected submit button etc. That all works just as you want it to. Now
you want to *in addition to the existing submit button* offer a link up
at the top of the page that will submit that same form. Do you want
that link to a) have exactly the same effect as the submit button--no
more, no less, or b) have the same effect as the submit button *plus*
tack an extra parameter & value onto :params? (Or c) something else?)

If a)--I would think Fred's earlier suggestion to use javascript to do a
my_form.submit() should work. I don't know the best way to get rails to
generate that (link_to_function("click me", "my_form.submit()") maybe?)
but no doubt others here will. If b) it's probably a little more
involved (javascript stuffs your parameter in a hidden field created in
your form maybe, and *then* does a my_form.submit()?).

HTH,

-Roy

Roy Pardee wrote:
or b) have the same effect as the submit button *plus*

tack an extra parameter & value onto :params? (Or c) something else?)

If b) it's probably a little more

involved (javascript stuffs your parameter in a hidden field created in
your form maybe, and *then* does a my_form.submit()?).

Exactly, I need to pass another parameter and that is where I am stuck
right now. The only option I can think of is to use some ajax and have
it pass a parm in when someone clicks the link and have it return
nothing and then have that same click call form.submit() afterwards. I
am about to try this now but it seems like 1) it will be really slow and
2) it might not work. We will see.

I just dont know a way to pass the extra param as well as submitting the
form.

Thanks a lot,

Chris

You could simply use a hidden_field

Thorsten Mueller wrote:

You could simply use a hidden_field

I could be wrong seeing I am not too familiar with hidden fields but I
dont think that would help. I have a list of numbers at the top
representing different questions. If the user clicks on "1" I want to
pass in the "1" and submit the form, if they click "6" I want to pass in
the "6" and submit the form. From what I understand about hidden fields
there is no way to pass the "1" or "6" into the hidden field, correct?

Chris

Chris Hickman wrote:

Thorsten Mueller wrote:

You could simply use a hidden_field

I could be wrong seeing I am not too familiar with hidden fields but I
dont think that would help. I have a list of numbers at the top
representing different questions. If the user clicks on "1" I want to
pass in the "1" and submit the form, if they click "6" I want to pass in
the "6" and submit the form. From what I understand about hidden fields
there is no way to pass the "1" or "6" into the hidden field, correct?

Chris

nope, that's a perfect use case for a hidden field.
those numbers should just do some js to set the value of the field

Thorsten Mueller wrote:

nope, that's a perfect use case for a hidden field.
those numbers should just do some js to set the value of the field

Oh so it keeps everything client side so it wont be as slow and then the
value will get passed in with the form. So, I can just put a call to a
javascript method inside the hidden field for :value => and it will get
passed through correctly.

Oh so it keeps everything client side so it wont be as slow and then the
value will get passed in with the form. So, I can just put a call to a
javascript method inside the hidden field for :value => and it will get
passed through correctly.

ok, it depends on how exactly you use the hidden field (and if it's
hidden_field or hidden_field_tag)

most simple case:

<%= hidden_field_tag 'number' %>

will generate:

<input id="number" name="number" type="hidden" />

so the number can define an
onchange = "$('number').value = '1'"

the id/name may depend on your setup, but just have a look at the
generated html to get that.

That makes sense. Thanks a lot, I really appreciate your help.

Chris