JS validation on a form/submit tag? Like :condition=>

Hallo – is there a way anyone know of that I can add a :confirm clause
to a form submit? Something like:
<%= submit_tag ‘commit’, :confirm=>“are you certain?” %>
Does anyone know how to achieve this?

My guess is that would need to go in the onclick handler for the form.


From the top of my head I remember this.

However, check it in different browsers first!

Hi – the way I did it was like this:
I created a helper method in ‘application_helper.rb’:

def confirm_submit_tag(value=“submit”, msg=“Are you sure?”)
“<input type=“submit” value=”#{value}" onclick=“return
confirm(’#{msg}’);” />"

& then, in the rhtml (inside the form), I can just use

<%= confirm_submit_tag ‘commit’, “This will commit the changes you
made.” %>

It works well in firefox & IE.
Cheers for the input!

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