开发者

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

开发者 https://www.devze.com 2022-12-22 07:03 出处:网络
I need to have a checkbox which ajax-submits a form. The following code throws an error \"index 112009 out of string\". What\'s

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开发者_如何学C for any help with this!

Tom


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号