By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,851 Members | 1,051 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,851 IT Pros & Developers. It's quick & easy.

Ajax - createElement Duplicating Anchors

jenkinsloveschicken
P: 56
Good afternoon. I am new to Ajax, and seem to have an issue in my use of createElement. Here is the code:

Expand|Select|Wrap|Line Numbers
  1.   xmlHttp.onreadystatechange=function()
  2.     {
  3.     if(xmlHttp.readyState==1)
  4.       {
  5.       var processing = document.createElement('img');
  6.       processing.setAttribute('src', 'img/loading_main.gif');
  7.       document.getElementById("empReport").appendChild(processing);
  8.       }
  9.     if(xmlHttp.readyState==4)
  10.       {
  11.       document.getElementById("empReport").innerHTML=xmlHttp.responseText;
  12.       }
  13.     }
  14.  
This is integrated with an existing classic ASP reporting application. It works to display the processing image, but duplicates the <img> anchor and I have tried and failed to determine why.

I am hoping someone can give me some insight on what I am doing wrong here.

Best Regards,
Jenkins
Oct 29 '08 #1
Share this Question
Share on Google+
3 Replies


acoder
Expert Mod 15k+
P: 16,027
It's duplicating it because you're creating a new image element each time. If all you want to do is display it, get the element by its ID and then set the display property:
Expand|Select|Wrap|Line Numbers
  1. document.getElementById("imgID").style.display = 'block';
Oct 30 '08 #2

jenkinsloveschicken
P: 56
Thank you for your assistance. Worked like a charm!
Oct 30 '08 #3

acoder
Expert Mod 15k+
P: 16,027
You're welcome. Glad it did!
Oct 30 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.