Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

submit_tag with javascript function

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 following ,

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

I googled the problem but I couldn't find a solution.Please any one give a solution.

like image 909
karthi_ms Avatar asked Sep 22 '11 06:09

karthi_ms


2 Answers

try onclick

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

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

like image 183
Mahesh Avatar answered Oct 17 '22 11:10

Mahesh


You can use something like this on the form tag

 <% form_for :bla, :html => { :onsubmit => 'blahblah;' } do |f| %>
like image 28
nateleavitt Avatar answered Oct 17 '22 10:10

nateleavitt