Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-02-2005, 01:38 PM   PM User | #1
stewb
New Coder

 
Join Date: Dec 2003
Location: WA, Australia
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
stewb is an unknown quantity at this point
Exclamation Random Image on page load problem

Hello all

I am having errors for some reason for the following script, can anyone help here?

What i want to do is randomize set images in the same location each time the same page is loaded by someone: It's driving me nuts !! The script is:


<head>

<script language="javascript">


function imgswp() {
var imgs = new Array("../Banners/0009.jpg","../Banners/0010.jpg","../Banners/0011.jpg","../Banners/0012.jpg")
document.getElementById("aimg").src = imgs[Math.floor(Math.random()*imgs.length)]
}
</script>

</head>

<body onLoad="imgswp()">

<div id="top2">
<h2>
<img border="0" img id="aimg" src="" width="430" height="85" >
</h2></div>

Last edited by stewb; 04-02-2005 at 01:51 PM..
stewb is offline   Reply With Quote
Old 04-02-2005, 02:11 PM   PM User | #2
stewb
New Coder

 
Join Date: Dec 2003
Location: WA, Australia
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
stewb is an unknown quantity at this point
Ahhh finally found the problem. All fixed now...
stewb is offline   Reply With Quote
Old 04-02-2005, 02:56 PM   PM User | #3
glenmac
Regular Coder

 
Join Date: Nov 2003
Location: Vancouver Island Canada
Posts: 139
Thanks: 0
Thanked 0 Times in 0 Posts
glenmac is an unknown quantity at this point
How?

To help others!
__________________
lantzvillecomputers.com
glenmac is offline   Reply With Quote
Old 04-04-2005, 03:44 AM   PM User | #4
stewb
New Coder

 
Join Date: Dec 2003
Location: WA, Australia
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
stewb is an unknown quantity at this point
Thumbs up

The problem was seemingly unrelated but vital. The code i used was fine, it was because i had other Javascript on the same page and forgot to seperate it properly in the header ie </script> and start another <script> for the new code.

In my header one set of code referred to a js page and the new code for this randomiser was on the same home page.

A debugger program would have found this for me quicker but i find without it i learn a lot more.
stewb is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:46 AM.


Advertisement
Log in to turn off these ads.