Forum: Ruby on Rails I feel stupid - help with Element.show

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
42172acdf3c6046f84d644cb0b94642c?d=identicon&s=25 Pat Maddox (pergesu)
on 2006-04-01 00:08
(Received via mailing list)
This isn't Rails-specific, and I'm sorry for that, but I haven't been
able to get a response in the #prototype/#javascript/#ror channels,
nor find anything via Google.

I have a form element that I want to be hidden when the page first
loads, and appear when a user clicks the link.  Here's the code:

<div id='signin-link'><%= link_to 'Sign In', '#', :onclick =>
"Element.show('signin-form')"  %></div>

<div id='signin-form'>
  <%= start_form_tag(signin_url)%>
    <%= text_field_tag :username %>
    <%= password_field_tag :password %>
    <%= submit_tag 'Sign In' %>
  <%= end_form_tag %>
</div>


In my CSS file I have
#signin-form {
  display: none;
}

Now checking out
http://wiki.script.aculo.us/scriptaculous/show/Element.show, I'm
pretty sure that's all I have to do.  However if I click on the link,
the form doesn't get shown.  No JS errors.  If I have the element
shown at the page start, I can hide/toggle it all I want.  Just can't
start off with display:none apparently.  I'm using Firefox 1.5.01 and
the javascript files that were installed with "rake rails:update".

Pat
6ec1e89eef5ce09fbfa56be5b6dd17b5?d=identicon&s=25 Adam Bloom (admanb)
on 2006-04-01 01:07
Try it with the style embedded. i.e:

<div id="signin-form" style="display:none">

I'm not sure what difference that would make, but that's what works for
me.
5b1b906e6d15f3c7b211dac6242e490b?d=identicon&s=25 albert elegance (Guest)
on 2006-04-01 01:09
(Received via mailing list)
If you set display: none in the CSS file, Javascript won't realize it.
You
have to manually specify style="display: none;" in the HTML.
42172acdf3c6046f84d644cb0b94642c?d=identicon&s=25 Pat Maddox (pergesu)
on 2006-04-01 01:18
(Received via mailing list)
Cool, that works, thanks for the help.
E813e9cc70159e103a64a5237c0d3ee2?d=identicon&s=25 Thomas Fuchs (Guest)
on 2006-04-01 01:37
(Received via mailing list)
The difference is that "display:none" in external CSS overwrites
the browsers default for the display attribute, which is (for most
elements)
either "block" or "inline", whereas setting it on the "style"
attribute you
can fall back to the browsers default later (which is what
Element.show does).

That's a bit of an annoyance with the CSS spec, that it doesn't seperate
how an element should "flow" on the page from whether it should
be displayed at all.

-Thomas

Am 01.04.2006 um 01:07 schrieb Adam Bloom:
This topic is locked and can not be replied to.