:with => javascript method call

I have a form and I am trying to pass a next_question param which will
hold a value that is returned by a javascript function. Is this
possible? I am new to using :with and javascript and have read
documentation on it as well as an entire page explaining it with
examples but I still dont really understand how to do this, or if it is
even possible.

:with => “'next_question='javascript: getNextQuestion()”

Thanks in advance,

chris

Chris H. wrote:

I have a form and I am trying to pass a next_question param which will
hold a value that is returned by a javascript function. Is this
possible? I am new to using :with and javascript and have read
documentation on it as well as an entire page explaining it with
examples but I still dont really understand how to do this, or if it is
even possible.

:with => “'next_question='javascript: getNextQuestion()”

Thanks in advance,

chris

What about the :compete call back. When using form_remote_tag I use
:complete to clear a text_field for example. I imagine if you had a div
with an id you could use that javaScript function to change the
innerText of that div upon complete to add the next question. Hope this
helps,

-S

On 9 Jun 2008, at 17:43, Chris H. wrote:

:with => “'next_question='javascript: getNextQuestion()”

I’ve got some examples here:

it is possible - what you don’t seem to have grasped yet is that the
entirety of the :with parameter should be a piece of javascript code.
Fred

On 9 Jun 2008, at 18:07, Chris H. wrote:

:with => “‘next_question=’+getNextQuestion()”

The problem is probably the getNextQuestion is not returning something
that is uri encoded (or not returning anything at all). Remember that
in javascript you need an explicit return statement, and use
encodeURIComponent.

Fred

One last question and then I am giving up. It seems like nothing is
getting passed over at all. The following should pass next_question to
the controller with a value of 6. In the controller I should be able to
access it by saying params[:free_response][:next_question] correct?

<% form_for(:free_response, :url => {:action => ‘next’, :question =>
@question.id}, :with => “‘next_question=’+encodeURIComponent(6)”) do
|form| %>

Sorry for all the questions I am just completely lost on this one. I
tried the encodeURIComponent() before and nothing changed so I kept
changing it around.

Chris

Fred,

I’m sorry, that was the page I was reading. I found a link to it in
another forum. I have tried several different ways of doing this and
none of them seem to be working for me. From one of the last 2 examples
on your page it seems like the following should work but I am not having
any luck.

:with => “‘next_question=’+getNextQuestion()”

I am glad to hear this is possible though.

Thanks

On 9 Jun 2008, at 18:40, Chris H. wrote:

|form| %>

Sorry for all the questions I am just completely lost on this one. I
tried the encodeURIComponent() before and nothing changed so I kept
changing it around.

:with is only for remote_form_for, link_to_remote etc… in your case
i’d probably use an onsubmit to update a hidden field

Fred

Thanks for your time and patience.