View Full Version : Modifiying script to support two variables

08-02-2006, 05:37 PM
I would've thought it would be easy, but either there's something I'm missing, or I've been mentally challenged for the past hour.

I have a script that loads an external banner ad page into my main page via ajax. The way the script is setup, you call it from body onload of the main page and the variable for the ad page's location is already set inside the script, so it just places the page/ad in the chosen div'd location.

The onload call is:


The script I am using currently is:

var page = "ads/topads.php";
function ajax(url,target) {
// native XMLHttpRequest object
document.getElementById(target).innerHTML = 'Loading New Banner Ad...';
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
req.onreadystatechange = function() {ajaxDone(target);};
req.open("GET", url+"?bustcache="+new Date().getTime(), true);
// IE/Windows ActiveX version
} else if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
req.onreadystatechange = function() {ajaxDone(target);};
req.open("GET", url+"?bustcache="+new Date().getTime(), true);
setTimeout("ajax(page,'topads')", 30000);
function ajaxDone(target) {
// only if req is "loaded"
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200 || req.status == 304) {
results = req.responseText;
document.getElementById(target).innerHTML = results;
} else {
document.getElementById(target).innerHTML="ajax error:\n" + req.statusText;

What I need is to make the location of the page it grabs set when I call it. Reason being is because I have two sets of ads on my main page that I want to handle like this. So basically, I want to be able to set all the options in the onload call so it would look like this:


Sorry if this sounds dumb, I know it does to me, and I feel dumb for not even being able to figure it out when I am usually great with javascript. Thanks in advance for any help you can give!

08-03-2006, 08:06 PM

...can no one lend a hand or even help walk me through it? can't be that difficult...