2010-03-10 49 views
2

我需要一個ajax提交表單的複選框。Ajax-submit form on checkbox onclick:why this error?

以下代碼將引發錯誤「索引112009超出字符串」。 這裏錯了什麼?

<% form_remote_tag :url => { whatever_url } do -%> 

<%= check_box_tag 'whatever', nil, whatever, { :onclick => "#{remote_function('this.form.submit();')}" } %> 

<% end -%> 

感謝您的任何幫助!

湯姆

+0

什麼是方法remote_function? – shingara 2010-03-10 14:35:48

+0

這是這個:http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper.html#M001653 – TomDogg 2010-03-10 15:24:54

回答

2

看來你是濫用remote_function幫手。它的目的是生成與link_to_remote等生成的相同的javascript,以更新帶有AJAX調用結果的div。在你的情況,你需要像

<%= check_box_tag 'whatever', nil, whatever, { :onclick => "$('your_form').onsubmit();" } %> 

onsubmit,不submit一件簡單的事情。這是因爲您需要通過AJAX提交表單的代碼存在於表單的onsubmit屬性中。