Problem submiting value, form_for, link-to-remote, javascrip

This is my form. It creates a comment in the database but won't pass the 'body' value. I think the problem is passing the variable to javascript. Can anyone help?

<% form_for :comment, :url=>story_comments_path(@story), :name => 'form' do |form| %>   <fieldset>        <label for="login">Comment:</label>        <div id="body"><%= form.text_field :body %></div>        <%= link_to_remote('comment',{ :url =>                                          {:controller => 'comments' ,                                           :action => 'create',                                           :story_id => @story.id,                                           :method => 'get',                                           :with => 'serialize_fields()' }}) %>     </fieldset>   <% end %>

This is the javascript.

<script> function serialize_fields(){   var fields = new Array();   fields.push(Form.Element.serialize('document.form.body'));   return fields.join('&'); } </script>

This is my form. It creates a comment in the database but won't pass the 'body' value. I think the problem is passing the variable to javascript. Can anyone help?

Your serialize_form method looks borked. You could use the remote_form_for method alternatively, prototype already provides a serialise method for forms - $('id_of_the_form').serialize() will serialise all then inputs in the form

Fred

Neil Bye wrote:

This is my form. It creates a comment in the database but won't pass the 'body' value. I think the problem is passing the variable to javascript. Can anyone help?

<% form_for :comment, :url=>story_comments_path(@story), :name => 'form' do |form| %>   <fieldset>        <label for="login">Comment:</label>        <div id="body"><%= form.text_field :body %></div>        <%= link_to_remote('comment',{ :url =>                                          {:controller => 'comments' ,                                           :action => 'create',                                           :story_id => @story.id,                                           :method => 'get',                                           :with => 'serialize_fields()' }}) %>     </fieldset>   <% end %>

This is the javascript.

<script> function serialize_fields(){   var fields = new Array();   fields.push(Form.Element.serialize('document.form.body'));   return fields.join('&'); } </script>

I tried this too

:with=>"'body' + $F('body')"

That doesn't work either. How can I pass this parameter?