0

I am having styling issues with my button. Currently I have this:

<%= link_to t(:add_to_cart), '#', :onclick => "$(this).parent().submit(); return false;", :type => "button", :class => "button primary" %>

which renders this:

<a href="#" class="button" onclick="$(this).parent().submit(); return false;">Add To Cart</a>

when I change the link_to to a button_to, I've got this:

<%= button_to t(:add_to_cart), '#', :onclick => "$(this).parent().submit(); return false;", :type => "button", :class => "button primary" %>

which renders this:

<input class="button primary" onclick="$(this).parent().submit(); return false;" type="submit" value="Add To Cart">

Unfortunately, the javascript no longer works. I can see the obvious change in the markup, but why does this no longer work? I'm a designer that dabbles in Rails, so please be gentle! Seems like this could be something pretty simple. I did try :url => '#' on the button_to, which gave me other styling issues, so I reverted.

1 Answer 1

1

what do you want to do with button ?

you use $(this).parent().submit(); ---> in jquery this part of code submit the form but button_to do this by default why you add it ??

then you use return false; ----> this prevent to submit form in javascript !!!

i hope i clarify something to you

Sign up to request clarification or add additional context in comments.

1 Comment

Fantastic, that worked. I removed the script and everything works as intended!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.