Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

:onclick doesn't work in button_to

im trying to call a function through onclick method of a button. here is the code:

      <%= button_to "Close" , :onclick => "show_back(), return false" %>

but it doesn't work, everytime i click the button an error occours

" No action responded to 29. Actions: checkout, create, destroy, edit, find_cart, index, new, save_order, show, and update "

how ever when i impliment the same thing in a href it works

     <a onclick="show_back();return false;" href="#."> Close </a>

can anyone plz tell me what im doing wrong, thanks in advance..

like image 363
Umer Hassam Avatar asked Mar 26 '11 09:03

Umer Hassam


Video Answer


2 Answers

you can try this

=link_to "value", "javascript:function()"

and add your class, if you use like bootstrap, you can try:

=link_to "value", "javascript:function()", class: 'btn btn-default'
like image 192
Lei Wang Avatar answered Sep 23 '22 14:09

Lei Wang


I was looking for something similar. My problem was that I wanted to fire an addCookie() function when a user click logged in.

Did that with:

<%= submit_tag 'Go', class: "ses_submit_btn", :onclick => "addCookie()" %>
like image 20
troxwalt Avatar answered Sep 22 '22 14:09

troxwalt