Banner rotating script problem

Subz

Seasoned Veteran
Joined
May 9, 2008
Messages
3,241
Reaction score
0
FP$
6
I seem to have a problem implicating a banner rotating script.

here is the code i have used in

index_body.html

Code:
<!-- INCLUDE overall_header.html -->

<!-- BANNER AD SCRIPT
*
*
* -->
<script type="text/javascript" language="javascript">

function randomads() {

var ads = new Array();
ads[0] = "http://google.co.uk/images/google-logo.gif";
ads[1] = "http://pixelraider.com";

var adlinks = new Array();
adlinks[0] = "http://google.co.uk";
adlinks[1] = "http://pixelraider.com/images/default-logo.gif"";


num=Math.floor(Math.random()*ads.length);

document.write("<a href=" +adlinks[num]+ " target=_blank>
<img src=" +ads[num]+ " border="0" width="468" height="60"></a>")
}

</script>
<!-- BANNER AD SCRIPT
*
*
*-->
<!-- IF U_MCP -->
	<div id="pageheader">
		<p class="linkmcp">[ <a href="{U_MCP}">{L_MCP}</a> ]</p>
	</div>

	<br clear="all" /><br />
<!-- ENDIF -->

<!-- INCLUDE forumlist_body.html -->

<!-- IF not S_IS_BOT or U_TEAM -->
    <span class="gensmall"><!-- IF not S_IS_BOT --><a href="{U_DELETE_COOKIES}">{L_DELETE_COOKIES}</a><!-- IF U_TEAM --> | <!-- ENDIF --><!-- ENDIF --><!-- IF U_TEAM --><a href="{U_TEAM}">{L_THE_TEAM}</a><!-- ENDIF --></span><br />
<!-- ENDIF -->

<br clear="all" />

<table class="tablebg" width="100%" cellspacing="1">
   <tr>
      <td class="cat" colspan="4"><h4 align="center">Site Showcase</h4></td>
   </tr>

   <tr>
      <td class="row1" align="center" valign="middle" width="25%">Block 1</td>
      <td class="row1" align="center" valign="middle" width="25%">Block 2</td>
      <td class="row1" align="center" valign="middle" width="25%">Block 3</td>
      <td class="row1" align="center" valign="middle" width="25%">Block 4</td>
   </tr>
   </table>

<!-- INCLUDE breadcrumbs.html -->

<!-- IF S_DISPLAY_ONLINE_LIST -->
	<br clear="all" />

    {$CA_BLOCK_START}
	{$CA_CAP2_START}<!-- IF U_VIEWONLINE --><a href="{U_VIEWONLINE}">{L_WHO_IS_ONLINE}</a><!-- ELSE -->{L_WHO_IS_ONLINE}<!-- ENDIF -->{$CA_CAP2_END}
	<table class="tablebg" width="100%" cellspacing="{$CA_SPACING}">
	<tr>
	<!-- IF LEGEND -->
		<td class="row1" rowspan="2" align="center" valign="middle"><img src="{T_THEME_PATH}/images/whosonline.gif" alt="{L_WHO_IS_ONLINE}" /></td>
	<!-- ELSE -->
		<td class="row1" align="center" valign="middle"><img src="{T_THEME_PATH}/images/whosonline.gif" alt="{L_WHO_IS_ONLINE}" /></td>
	<!-- ENDIF -->
		<td class="row1" width="100%"><span class="genmed">{TOTAL_USERS_ONLINE} ({L_ONLINE_EXPLAIN})<br />{RECORD_USERS}<br /><br />{LOGGED_IN_USER_LIST}</span></td>
	</tr>
	<!-- IF LEGEND -->
		<tr>
			<td class="row1 nobold"><b class="gensmall">{L_LEGEND} :: {LEGEND}</b></td>
		</tr>
	<!-- ENDIF -->
	</table>
	{$CA_BLOCK_END}
<!-- ENDIF -->

<!-- IF S_DISPLAY_BIRTHDAY_LIST && BIRTHDAY_LIST -->
	<br clear="all" />
    
    {$CA_BLOCK_START}
	{$CA_CAP2_START}{L_BIRTHDAYS}{$CA_CAP2_END}
	<table class="tablebg" width="100%" cellspacing="{$CA_SPACING}">
	<tr>
		<td class="row1" align="center" valign="middle"><img src="{T_THEME_PATH}/images/birthday.gif" alt="{L_BIRTHDAYS}" /></td>
		<td class="row1 nobold" width="100%"><p class="genmed"><!-- IF BIRTHDAY_LIST -->{L_CONGRATULATIONS}: <b>{BIRTHDAY_LIST}</b><!-- ELSE -->{L_NO_BIRTHDAYS}<!-- ENDIF --></p></td>
	</tr>
	</table>
	{$CA_BLOCK_END}
<!-- ENDIF -->

<br clear="all" />

{$CA_BLOCK_START}
{$CA_CAP2_START}{L_STATISTICS}{$CA_CAP2_END}
<table class="tablebg" width="100%" cellspacing="{$CA_SPACING}">
<tr>
	<td class="row1"><img src="{T_THEME_PATH}/images/stats.gif" alt="{L_STATISTICS}" /></td>
	<td class="row1 nobold" width="100%" valign="middle"><p class="genmed">{TOTAL_POSTS} | {TOTAL_TOPICS} | {TOTAL_USERS} | {NEWEST_USER}</p></td>
</tr>
</table>
{$CA_BLOCK_END}

<!-- IF not S_USER_LOGGED_IN -->
	<br clear="all" />

	<form method="post" action="{S_LOGIN_ACTION}">
	
	{$CA_BLOCK_START}
	{$CA_CAP2_START}<a href="{U_LOGIN_LOGOUT}">{L_LOGIN_LOGOUT}</a>{$CA_CAP2_END}
	<table class="tablebg" width="100%" cellspacing="{$CA_SPACING}">
	<tr>
		<td class="row1" align="center"><span class="genmed">{L_USERNAME}:</span> <input class="post" type="text" name="username" size="10" />&nbsp; <span class="genmed">{L_PASSWORD}:</span> <input class="post" type="password" name="password" size="10" />&nbsp; <!-- IF S_AUTOLOGIN_ENABLED --><span class="gensmall">{L_LOG_ME_IN}</span> <input type="checkbox" class="radio" name="autologin" />&nbsp;<!-- ENDIF --> <input type="submit" class="btnmain" name="login" value="{L_LOGIN}" /></td>
	</tr>
	</table>
	{$CA_BLOCK_END}
	{S_FORM_TOKEN}
	</form>
<!-- ENDIF -->

<br clear="all" />

<table class="legend">
<tr>
	<td width="20" align="center">{FORUM_NEW_IMG}</td>
	<td><span class="gensmall">{L_NEW_POSTS}</span></td>
	<td>&nbsp;&nbsp;</td>
	<td width="20" align="center">{FORUM_IMG}</td>
	<td><span class="gensmall">{L_NO_NEW_POSTS}</span></td>
	<td>&nbsp;&nbsp;</td>
	<td width="20" align="center">{FORUM_LOCKED_IMG}</td>
	<td><span class="gensmall">{L_FORUM_LOCKED}</span></td>
</tr>
</table>

<!-- INCLUDE overall_footer.html -->

the link to the forum is http://forumadverts.net
 
Lots of problems there

firstly you've put the code in a function, but you haven't called the function.

secondly there is an extra " on the second adlink

thirdly there are " in the document.write bit that haven't be escaped.

lastly there is no need to use two arrays when you can use multidimensional arrays.

anyway I rewrote it a bit:

Code:
<script type="text/javascript" language="javascript">function swg_fa_randomads() {var ads = new Array();

// List of banners, first item = banner url, second item = link url
ads[0] = new Array('http://google.co.uk/images/google-logo.gif', 'http://google.co.uk');
ads[1] = new Array('http://pixelraider.com/images/default-logo.gif', 'http://pixelraider.com');
ads[2] = new Array('Image URL', 'Link URL');

// do not edit
i=Math.floor(Math.random()*ads.length);document.write('<a href="'+ads[i][1]+'" target="_blank"><img src="'+ads[i][0]+'" border="0" width="468" height="60"></a>');} swg_fa_randomads();</script>

works fine on my test server 🙂
 
Thanks Spyka, i'll give that a go and post the results -🙂-
 
Back
Top Bottom