1

I know that if you just type something like <button>Something</button> outside a form_for in rails, it will create a useless button. But I want to create buttons within this form_for to be handled by JavaScript. Is there a way to create it?

3 Answers 3

1

This will create useless buttons that can be handled by JavaScript.

Plain HTML:

<input type="button" onclick="alert('Hello.')" value="Click Here" />

Rails:

<%= submit_tag "Click Here", :type => 'button', :onclick => 'alert("Hello.")' %>
Sign up to request clarification or add additional context in comments.

Comments

0

If you're not looking for Rails to use it, why not just use the plain html inside the form_for?

<%= form_for @record do |f| %>

  ## inputs ##

  <button>Something</button>
  <%= f.submit %>

<% end %>

Comments

0

Check out this answer: How do I create multiple submit buttons for the same form in Rails?

<% form_for(something) do |f| %>
    ..
    <%= f.submit 'A' %>
    <%= f.submit 'B' %>
    ..
<% end %>

Comments

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.