Ajax-submit form on “check box onclick ”: why this error?

坚强是说给别人听的谎言 提交于 2019-12-06 09:20:31

问题


I need to have a checkbox which ajax-submits a form.

The following code throws an error "index 112009 out of string". What's wrong here?

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

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

<% end -%>

Thanks for any help with this!

Tom


回答1:


Seems you are abusing the remote_function helper. Its purpose is to generate the same javascript as is generated with link_to_remote et al., like, to update a div with the result of an AJAX call. In your case you need a simple thing like

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

Note the onsubmit, not submit. This is because the code you need to submit the form via AJAX is present in the onsubmit attribute of the form.



来源:https://stackoverflow.com/questions/2417561/ajax-submit-form-on-check-box-onclick-why-this-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!