最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Rails: Form confirm message with data from the submitted form - Stack Overflow

programmeradmin2浏览0评论

Trying to make a custom :confirm message for a rails form that returns data from the submitted form--not just a static string.

<% form_for @foo do |f| -%>
<% f.text_field :number_of_bars -%>
<% f.submit :confirm => Are you really sure you want to use ##number_of_bars## bars? -%>

The idea is if the user puts in the number 3 in the number of bars text field the confirm message would show up like this: "Are you really sure you want to use 3 bars?"

Any ideas how to do this?

Trying to make a custom :confirm message for a rails form that returns data from the submitted form--not just a static string.

<% form_for @foo do |f| -%>
<% f.text_field :number_of_bars -%>
<% f.submit :confirm => Are you really sure you want to use ##number_of_bars## bars? -%>

The idea is if the user puts in the number 3 in the number of bars text field the confirm message would show up like this: "Are you really sure you want to use 3 bars?"

Any ideas how to do this?

Share Improve this question asked Mar 2, 2010 at 21:57 Kenji CroslandKenji Crosland 3,0346 gold badges34 silver badges43 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

Try this:

<%= f.submit :onclick => "return confirm('Are you really sure you want to use '+
          document.getElementById('number_of_bars_id').value + '?' )" %>

Replace the number_of_bars_id with the id of your field.

If you google a bit you will find a way for this to work with :confirm.

发布评论

评论列表(0)

  1. 暂无评论