Welcome to WebmasterWorld Guest from 54.146.180.94

Forum Moderators: open

Having problems with the script showing up in multiple locations.

Having problems with the script showing in multiple locations.

   
1:21 pm on May 30, 2013 (gmt 0)


How can i make this scripts used in the same page muliple times. im only to place once in the same page.

[code]<script type="text/javascript">
function initArray() {

this.length = initArray.arguments.length;
for (var i = 0; i < this.length; i++) {
this[i] = initArray.arguments[i];
}
}

link = new initArray(
"http:/[smilestopper]/example.com/page1",
"http:/[smilestopper]/example.com/page2",
"http:/[smilestopper]/example.com/page3",
"http:/[smilestopper]/example.com/page4",
"http:/[smilestopper]/example.com/page5",
"http:/[smilestopper]/example.com/page6"
);

image = new initArray(
"http:/[smilestopper]/example.com/images/banner_1.jpg",
"http:/[smilestopper]/example.com/images/banner_2.jpg",
"http:/[smilestopper]/example.com/images/banner_3.jpg",
"http:/[smilestopper]/example.com/images/banner_4.jpg",
"http:/[smilestopper]/example.com/images/banner_5.jpg",
"http:/[smilestopper]/example.com/images/banner_6.jpg"
);

text = new initArray(
"Example 1 Title",
"Example 2 Title",
"Example 3 Title",
"Example 4 Title",
"Example 5 Title",
"Example 6 Title"
);

function getRandom(){
var core = Math.floor(Math.random()*6); // amount of items in array
displayBanner(core)
}

function displayBanner(theNum){
var ranlink = link[theNum];
var ranimage = image[theNum];
var rantext = text[theNum];

//document.write('<a href=\"' +ranlink+ '\" target=\"_blank\"><img src=\"'+ranimage+'\" border="0" alt=\"'+rantext+'\"></a>');
document.getElementById('theImg').alt=rantext;
document.getElementById('theImg').src=ranimage;
document.getElementById('theLink').href=ranlink;
}
</script>

<a href="#" target="_blank" id="theLink"><img src="" border="0" alt="" id="theImg"></a>

<script type="text/javascript">
getRandom();
setInterval("getRandom()", 6000);
</script> [/code]
12:25 am on May 31, 2013 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



I would alter the displayBanner function so that it took a some other paramters.

function displayBanner(theNum,ImageID,LinkID){
var ranlink = link[theNum];
var ranimage = image[theNum];
var rantext = text[theNum];

document.getElementById(ImageID).alt=rantext;
document.getElementById(ImageID).src=ranimage;
document.getElementById(LinkID).href=ranlink;
}

Then update
function getRandom(){
var core = Math.floor(Math.random()*6); // amount of items in array
displayBanner(core,'theImg','theLink');

core = Math.floor(Math.random()*6); // amount of items in array
displayBanner(core,'theImg2','theLink2');
...etc.

}
 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month