Passing a JavaScript variable through a Rails params hash

Hi guys, hoping someone can give me a pointer with this?

I have a Javascript variable that I'm updating dynamically as a user interacts with the page. I want the user to be able to save it's value at any time along with some text data in a pop-up form, so the best way I can think of is to pass it through the params hash without writing it into the form. I'm not totally sure how to do this though?

The only practical solution i've got is for a hidden field line in the form to be dynamically generated when the user goes to save it, but this feels like overkill to me. Does anyone have any suggestions for a neater way to do it?

Thanks,

Jon

Hi

You need to change the target attrubute of the form tag. Give it an id
if it doesn't have one: form_tag({:action =>"update"}, {:id => "the_form"}) do ... Then if using prototype, $('the_form').target += '&varname='+var;

Mind you URL encode the params value. You can use the escapeHTML
string class to encode it properly if using prototype. I think there
is also an escape function :wink:

Blog: http://random8.zenunit.com/ Twitter: http://twitter.com/random8r Learn: http://sensei.zenunit.com/ New video up now at http://sensei.zenunit.com/ real fastcgi rails
deploy process! Check it out now!