Delete div content automatically after 2 seconds

Hi everyone,
I’d like to display a text in a div (an error message returned from an
ajax
form) for 2 seconds and then delete the div content.
I do not want the div itself to fade out using scriptacolous - I want
the content itself overwritten with an empty string.

Is there a way of doing that in rails?

Thanks!

The best way of doing this is in Javascript. Scriptaculous is purely an
effects framework and has in and of itself nothing to do with Rails. If
you
want to fade out/slide out, etc, then you can add such an effect later.

For just deleting the error div after 2 seconds, you’ll need to use this
Javascript (using Prorotype):

setTimeout(2000, deleteDiv(‘div_id’));

function deleteDiv(div) {
// Effect call can go here
Element.remove(div);
}

Where this goes of course depends on how the error div is displayed. If
this
is a full page refresh, then a simple tag after the div will
work.

Jason

Ehud R. wrote:

Hi everyone,
I’d like to display a text in a div (an error message returned from an
ajax
form) for 2 seconds and then delete the div content.
I do not want the div itself to fade out using scriptacolous - I want
the content itself overwritten with an empty string.

Is there a way of doing that in rails?

Thanks!

RJS can contain raw JavaScript, so I’d make the result of the Ajax call
a bit of RJS rather than HTML. The RJS can set the div contents to
message text, then add a timeout function as above to replac it in 2s
with “”.

A.

You can also achieve this with RJS / Rails Helpers:

if the error message is set thorugh an AJAX response, you would do
something like in the rjs partial you render for the response:

page.replace_html :div_id “Your erro message here”
page.delay(2) do
page.replace_html :div_id, “”
end

if it’s a complete page refresh:

<%= @error_msg

On 19 Apr., 15:19, Alan F. [email protected]