Problem with javascript

Random things go here

Problem with javascript

Post by DrRoach on Mon Jun 03, 2013 9:25 am
([msg=75932]see Problem with javascript[/msg])

Hi I'm having a problem with some javascript to select a random picture. I have another seperatee script on the same page which works fine. Please help.
Code: Select all
<img id="home_thumbnail_images" src="home_thumbnail1.jpg" onLoad="thumbnail_image_generator">
<img id="home_thumbnail_images" src="home_thumbnail2.jpg" onLoad="thumbnail_image_generator">
<img id="home_thumbnail_images" src="home_thumbnail3.jpg" onLoad="thumbnail_image_generator">
<img id="home_thumbnail_images" src="home_thumbnail4.jpg" onLoad="thumbnail_image_generator">
<img id="home_thumbnail_images" src="home_thumbnail5.jpg" onLoad="thumbnail_image_generator">
<img id="home_thumbnail_images" src="home_thumbnail6.jpg" onLoad="thumbnail_image_generator">
<script language="javascript">
<!--
<!-- Code to show random thumbnbail pictures -->
function thumbnail_image_generator()
{
var image_number=Math.floor((Math.random()*10)+1);
var x=document.getElementById("home_thumbnail_images")
var start_src='home_thumbnail';
var end_src='.jpg';
x.src=start_src+image_number+end_src;
}
//-->
</script>
DrRoach
Poster
Poster
 
Posts: 155
Joined: Fri Feb 22, 2013 6:53 pm
Blog: View Blog (0)


Re: Problem with javascript

Post by fashizzlepop on Mon Jun 03, 2013 2:40 pm
([msg=75937]see Re: Problem with javascript[/msg])

I'm pretty sure each image should have a different ID, then call it by it's ID using some random function. (Not sure if this works, but that's my first guess.)
The glass is neither half-full nor half-empty; it's merely twice as big as it needs to be.
User avatar
fashizzlepop
Developer
Developer
 
Posts: 2304
Joined: Sat May 24, 2008 1:20 pm
Blog: View Blog (0)


Re: Problem with javascript

Post by DrRoach on Mon Jun 03, 2013 3:59 pm
([msg=75938]see Re: Problem with javascript[/msg])

Ok thanks II'll try it now
DrRoach
Poster
Poster
 
Posts: 155
Joined: Fri Feb 22, 2013 6:53 pm
Blog: View Blog (0)


Re: Problem with javascript

Post by brutal_hacker on Mon Jun 03, 2013 4:52 pm
([msg=75942]see Re: Problem with javascript[/msg])

Just from a quick search id look at this one http://codegrad.hub.ph/displaying-random-image-with-javascript/
brutal_hacker
Experienced User
Experienced User
 
Posts: 58
Joined: Fri Apr 19, 2013 1:03 pm
Blog: View Blog (0)



Return to Off-Topic

Who is online

Users browsing this forum: No registered users and 0 guests