AJAX issue: replace followed by show is not working

Hi,

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
/>#{@error_message}</div>"
  page[:add_a_tag_error].show

end

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>");
$("add_a_tag_error").show();
} 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)
page[:add_a_tag_error].show

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

Thanks.

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}"
page[:add_a_tag_error].show

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>
</div>

you have 2 divs with the same id.

Chris

Thanks Chris.

That solved the problem.

- Neeraj