homepage Welcome to WebmasterWorld Guest from 54.242.126.9
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
DIV content replaces the enitre page when appendChild is called
refresh ad div appendChild createElement
MDiddy

5+ Year Member



 
Msg#: 3405664 posted 9:38 pm on Jul 26, 2007 (gmt 0)

First post here…

I need to refresh a div which contains an ad while the rest of the page stays the same. I think I'm pretty close by reading the previous posts on this site, but one odd thing is tripping me up and I can't figure out why. When I call my function to refresh the div, it replaces everything on the page instead of just swapping out the div. I'd appreciate any help from you js experts!


<script type="text/javascript">
function adBump(rand){
//setup ad call. returns a doc.write command from ad server
var adcall = "http://www.example.com?"+rand+"other_paramters";

//adds the advertisement graphic above the ad when it loads.
document.getElementById("adLabel").innerHTML = "<img src='http://www.example.com/images/adv_180x9.gif' width='180' height='9' alt='Advertisement'>";

//selects ad div, empties it then appends the new js call.
var b = document.getElementById("ad");
b.innerHTML = "";
var js = document.createElement("script");
js.type = "text/javascript";
js.src = adcall;
b.appendChild(js);

}
</script>

<div id="adArea">
<div id="adLabel">Ad label goes here</div>
<div id="ad">Ad goes here</div>
</div>

[edited by: DrDoc at 7:27 am (utc) on July 28, 2007]
[edit reason] Examplified URLs [/edit]

 

Drag_Racer

5+ Year Member



 
Msg#: 3405664 posted 9:54 pm on Jul 26, 2007 (gmt 0)

I don't see anything wrong with your code to cause this.

The problem may be in the script you are loading from the 'adcall' url.

If I were to create what your trying to accomplish, I may use AJAX to retrieve the ad and replace the content in the 'ad' div, just my thought...

MDiddy

5+ Year Member



 
Msg#: 3405664 posted 10:00 pm on Jul 26, 2007 (gmt 0)

Thanks alot for the direction. I'm not an ajax/js expert. Can you provide some code or a link where I can learn more?

Drag_Racer

5+ Year Member



 
Msg#: 3405664 posted 10:22 pm on Jul 26, 2007 (gmt 0)

here's a good place to start

[developer.mozilla.org...]
[w3schools.com...]
[sitepoint.com...]

MDiddy

5+ Year Member



 
Msg#: 3405664 posted 9:39 pm on Jul 27, 2007 (gmt 0)

OK Thanks for the direction…I set up an XMLHTTPRequest object and I'm able to test local files, but when I put the full URL to our ad server in, the ononreadystatechange function doesn't fire, even for an error. I've tried using 'GET' & 'POST' and neither seem to work. The server's address is on the same domain as I'm using to test, but their subdomains are different, i.e. foo.example.com, and bar.example.com. Can anyone offer any suggestions?

[edited by: DrDoc at 7:28 am (utc) on July 28, 2007]
[edit reason] Examplified URLs [/edit]

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved