0

I am trying to show div by clicking on a button form. I know its wrong just not to sure what to write, and should i write it on my javascript page or just in the view.

<%= submit_tag "Next Step", :type => 'button', :onclick => '$('#devregothinf').hide();' %>

<div id="devregothinf">
  <h2>General Information</h2>
  <%= render 'geninfor_step', form: f %>
</div>

i am getting an error as follow

syntax error, unexpected $end, expecting ')'
5
  • If you wanted to show the div, then why have you written hide first? Commented Dec 13, 2012 at 4:30
  • its actually show on this part, i am trying to toggle, i just cant get onclick div.show Commented Dec 13, 2012 at 4:30
  • What is your requirement, can you make me clear? Commented Dec 13, 2012 at 4:31
  • its a multi step form wizard, i just want to click on the next button to show the next part of the form Commented Dec 13, 2012 at 4:33
  • Write what I am posting. Commented Dec 13, 2012 at 4:33

3 Answers 3

1

Write as following:

<span onclick = "$('#devregothinf').slideToggle('slow');"> Next Step </span>

<div id="devregothinf" style="display:none;">
 <h2>General Information</h2>
 <%= render 'geninfor_step', form: f %>
</div>
Sign up to request clarification or add additional context in comments.

5 Comments

Otherwise you can write $('#devregothinf').show('slow'); also
so instead of using a submit form i should use a span?
Yes, better writing something else rather traditional submit tag
It works, but i don't see a mouse over it, would css fix it? span:hover of some sort?
You can put your styles according your wish. Eg:<span style="cursor:pointer; color:#AF12ED;" onclick = "$('#devregothinf').slideToggle('slow');"> Next Step </span>
1

If you're trying to get it to show and not hide, you just need to change $('#devregothinf').hide(); to $('#devregothinf').show();

Comments

1

You could do something like this

view (app/views/home.html.erb)

<%= link_to 'Next Step', 'home/next_step', :remote => true %>

<div id="devregothinf">

controller (app/controllers/home_controller.rb)

def next_step
  <your code>
  respond_to do |format|
      format.js
  end
end

*view (js.erb) (app/views/next_step.html.erb)*

$("#devregothinf").html("<%= raw escape_javascript(render(:partial => 'form')) %>")

*view (app/views/_form.html.erb)*

Your form partial

HTH

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.