Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rotating banners

Status
Not open for further replies.

Bashdon

Technical User
Feb 3, 2009
7
GB
Hi all

I have the following script that I want to use to rotate banners at the top of my web page ( every time the page is reloaded. I notice that this script swaps the background image in a divide, but what I want it to do is swap a GIF banner image instead of the background.
I know that I need to use document.write but am not sure where I need to make the changes to the script.

Any help would be really appreciated!!! Many thanks.

Paul


<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<title>Random Pictures</title>
<style type="text/css" title="text/css" media="all">
<!--
#header
{
position: absolute;
margin-top: 100px;
margin-left: 100px;
width: 468px;
height: 60px;
background-image: url(images/pic1.gif);
}
-->
</style>
<script type="text/javascript" language="javascript">
<!--
function swapPic()
{
if(document.getElementById)
{
var thePicture=document.getElementById("header";
var picPath="images/pic"+rnd(4)+".gif";
thePicture.style.background="url("+picPath+"";
}
}

function rnd(n)
{
return Math.floor(Math.random() * n) + 1;
}

//-->
</script>
</head>
<body onload="swapPic()">
<div id="header"></div>

</body>
</html>
 
The following has an error in it that will terminate the Javascript function:
Code:
var thePicture=document.getElementById("header";
You need a closing parenthesis. If you actually have a closing parenthesis, then in the future you need to copy and paste your code so we see EXACTLY what you have that could be causing your problem(s).

The line of code that changes the background picture is also missing a closing parenthesis, if you're going to display the banner graphic that way.

Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top