submit_tag with javascript function

前端 未结 4 2222
灰色年华
灰色年华 2021-02-20 05:41

I am new to rails.I want to call a javascript function when click the submit button.I used submit_tag , but the function did not get triggered.I want some thing like the followi

相关标签:
4条回答
  • 2021-02-20 06:22

    You can try

    <%= submit_tag , :onclick => "return validateform()" %>
    

    OR

    You can Use button_to_function

    <%= button_to_function "Greeting", "validateform()" %>
    

    And in your Javascript function, if all the validations pass, submit the form.

    0 讨论(0)
  • 2021-02-20 06:24

    You would do it in the form_tag...

    <%= form_tag({:action => :whatever}, {:onSubmit => 'return validateform();'} ) %>

    0 讨论(0)
  • 2021-02-20 06:29

    try onclick

    <%= submit_tag , :onclick => "return validateform();" %>
    

    or if you want to use onsubmit you can use that in your form_tag.

    0 讨论(0)
  • 2021-02-20 06:33

    You can use something like this on the form tag

     <% form_for :bla, :html => { :onsubmit => 'blahblah;' } do |f| %>
    
    0 讨论(0)
提交回复
热议问题