AJAX issue: replace followed by show is not working


I have following code in the html.

<div id="add_a_tag_error" style="display:none;">&nbsp;</div>

In case there is an error then following code gets executed.

if @error

  page[:add_a_tag_error].replace_html "<div id='add_a_tag_error'><br


Using firebug I noticed that following response is being sent.

try {
$("add_a_tag_error").update("<div id='add_a_tag_error'><br />Error.
try again!</div>");
} catch (e) {

But I don't see the error message on the browser.

However if I only execute this line the I see the error message (
given that I change &nbsp; to something else)

It seems to me that AJAX will not work in the case of replace followed
by show. Anyone knows how to fix this issue:?


replace_html replaces the content of the element, not the entire element itself.

you want to do:

page[:add_a_tag_error].replace_html "<br/>#{@error_message}"

which will result in:

<div id="add_a_tag_error"><br/>Error try again!</div>

the way you were doing it, the results would have been

<div id="add_a_tag_error" style="display:none">
  <div id="add_a_tag_error"><br/>Error try again!</div>

you have 2 divs with the same id.


Thanks Chris.

That solved the problem.

- Neeraj