Turn element hidden by default (ajax question)

(this is my first post on the ruby forum. If this is not the right place
for this type of question please let me know).

Ajax question
I have a checkbox that toggles the visibility of another element (a text
field) with the code:

Appear! <%= check_box :object_name, :method, :onClick => "Element.toggle('text_field_to_toggle')" %> <%= text_field :object_name, :method, :disabled => 'true' %>

--- the text field is: --- <%= text_field :object_name, :text_field_to_toggle %> -- It works well, the only problem is that it HIDES the text field which is initialy visible. How can i make the the initial state of an element hidden so it can be toggled to visible. Is there a parameter on the text box element that can set the initial state hidden or it should be implemented in javascript? Thank you in advance.

John Brown <[email protected]…> writes:

“Element.toggle(‘text_field_to_toggle’)” %>
box element that can set the initial state hidden or it should be
implemented in javascript?
Thank you in advance.

I think that you just have to write your tag like this :
<%= text_field :object_name, :text_field_to_toggle , :style => “display:
none” %>

The rule “display: none” must be inline and not in a separate css file
if you
want Element.toggle working properly.


Frantz Gauthier

Just a general piece of advice, using css to set the visibility to
none is fine but bear in mind that if someone hasn’t got javascript
enabled that element will never appear.

I’ve always found that using javascript to hide elements is better
since that way you don’t obscure anything from people who have it
turned off.

A function like the following will hide everything with a class name
of ‘hideme’.

Event.observe(window, ‘load’,
function() { allNodes = document.getElementsByClassName(“hideme”);
for(i = 0; i < allNodes.length; i++) {
allNodes[i].style.display=“none”;
} }
);

If you don’t need to hide a whole class of items then target by ID for
performance reasons.

Ross

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs