Hi,
I have the following code
<%= button_to_function “Hide”, “Element.toggle(‘mytext’);”%>
which does toggle the invisiblity of the text just fine, But want I want
via ajax magic, is to also toggle the button text, so it will now
display “Show” when I have toggled the invisiblity of the Div.
Thanks for any help.
John
John L. wrote:
Hi,
I have the following code
<%= button_to_function “Hide”, “Element.toggle(‘mytext’);”%>
which does toggle the invisiblity of the text just fine, But want I want
via ajax magic, is to also toggle the button text, so it will now
display “Show” when I have toggled the invisiblity of the Div.
Thanks for any help.
John
To toggle text back and forth like that, you need to test whether or not
the element is visible so the javascript knows what to make the button
say. Try attaching an RJS block that looks something like:
<%= button_to_function ‘Hide’ do |page|
page << “if ($(‘mytext’).visible) {”
page[‘id-of-button’].hide
page[‘id-of-button’].value = ‘Show’
page << “} else {”
page[‘id-of-button’].show
page[‘id-of-button’].value = ‘Hide’
page << “}”
%>
John L. wrote:
Hi,
I have the following code
<%= button_to_function “Hide”, “Element.toggle(‘mytext’);”%>
which does toggle the invisiblity of the text just fine, But want I want
via ajax magic, is to also toggle the button text, so it will now
display “Show” when I have toggled the invisiblity of the Div.
Thanks for any help.
John
See the example above for one way of doing it - this has nothing to do
with AJAX though; its just simple javascript.