How can i add a confirmation dialog to a submit_tag?

When i use button_to or link_to, i can easily request a confirmation
dialog with (for example)

<%= button_to “Delete this story”,
{ :controller => “story”, :action => “delete”, :id => @story.id },
:confirm => “Delete story: are you sure?” %>

I also want to do this for the submit buttons on my forms, which are
“submit_tag” rather than “button_to”. But it doesn’t seem to be
possible, looking at the submit_tag source or trying it in my code
(unless i’m just being dumb).

Can anyone explain how i can do this please?

thanks!

<%= submit_tag(‘Delete checked articles’, :onclick => “return
confirm(‘Are you sure you want to delete this article?’)”) %>

Adam

Adam C. wrote:

<%= submit_tag(‘Delete checked articles’, :onclick => “return
confirm(‘Are you sure you want to delete this article?’)”) %>

Adam
Thanks adam, but i couldn’t get this to work. Someone else suggested a
variation that does work fine though:

<%= submit_tag “Submit Reeply”,
:onclick => “return #{confirm_javascript_function(“Are you sure?”)}”
%>

thanks, max

This one works for me. Do not forget {}
<%= submit_tag value=‘OK’, {:onclick => “return confirm(‘Are you sure
you want to delete this article?’)” }%>

bye Zdenek

On 5 Záø, 09:57, Max W. [email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs