Mr_J Posted March 26, 2009 Share Posted March 26, 2009 Hi all, I have a page using some JavaScript. On-load or refresh a new image will display. This works 100% but how can I make it to display for e.g. 3 images? I have about 10 products on show or special and I want to "showcase" 3 images/products on the page. In my <head> tag: <SCRIPT LANGUAGE="JavaScript"> <!-- Begin var randomTWD = 0; var DoIt = 0; images = new Array; images[1] = new Image(); images[1].src = "prod/bpmonitors/bp1.PNG"; images[2] = new Image(); images[2].src = "prod/oxygen/1.PNG"; images[3] = new Image(); images[3].src = "prod/glucometers/EasyTouchGCU.PNG"; images[4] = new Image(); images[4].src = "prod/bpmonitors/bp2.PNG"; images[5] = new Image(); images[5].src = "prod/oxygen/2.PNG"; images[6] = new Image(); images[6].src = "prod/glucometers/EasyTouchGC.PNG"; function TWDpics() { var imgnum = images.length - 1; do { var randnum = Math.random(); randomTWD = Math.round((imgnum - 1) * randnum) + 1; } while (randomTWD == DoIt); DoIt = randomTWD; document.ImageHolder.src = images[DoIt].src; } // End --> </script> in the <body> tag: onLoad="TWDpics();" and where the image appear in page <img name="ImageHolder" src="prod/img/show.jpg" width="155" height="200" border="0" alt="by SA Micro Products"> I have tried to repeat the code where the image appear but no avail... Any help please Thanks Quote Link to comment Share on other sites More sharing options...
Mr_J Posted March 26, 2009 Author Share Posted March 26, 2009 I just want to show MORE THAN 1 image... can it be done? Quote Link to comment Share on other sites More sharing options...
Mr_J Posted March 26, 2009 Author Share Posted March 26, 2009 I got it right... Guess it is simple... All I did was to duplicate the part in the head and renamed the field/image name properties. I.e. SCRIPT LANGUAGE="JavaScript"> <!-- Begin var randomTWD = 0; var DoIt = 0; images = new Array; images[1] = new Image(); images[1].src = "prod/bpmonitors/bp1.PNG"; images[2] = new Image(); images[2].src = "prod/oxygen/1.PNG"; images[3] = new Image(); images[3].src = "prod/glucometers/EasyTouchGCU.PNG"; images[4] = new Image(); images[4].src = "prod/bpmonitors/bp2.PNG"; images[5] = new Image(); images[5].src = "prod/oxygen/2.PNG"; images[6] = new Image(); images[6].src = "prod/glucometers/EasyTouchGC.PNG"; function TWDpics() { var imgnum = images.length - 1; do { var randnum = Math.random(); randomTWD = Math.round((imgnum - 1) * randnum) + 1; } while (randomTWD == DoIt); DoIt = randomTWD; document.ImageHolder.src = images[DoIt].src; } // End --> </script> added the secont part as: <SCRIPT LANGUAGE="JavaScript"> <!-- Begin var randompoep = 0; var DoIt = 0; images = new Array; images[1] = new Image(); images[1].src = "prod/bpmonitors/bp1.PNG"; images[2] = new Image(); images[2].src = "prod/skaal/sk1.PNG"; images[3] = new Image(); images[3].src = "prod/glucometers/EasyTouchG.PNG"; images[4] = new Image(); images[4].src = "prod/bpmonitors/bp2.PNG"; images[5] = new Image(); images[5].src = "prod/oxygen/2.PNG"; images[6] = new Image(); images[6].src = "prod/glucometers/EasyTouchGC.PNG"; function poeppics() { var imgnum = images.length - 1; do { var randnum = Math.random(); randompoep = Math.round((imgnum - 1) * randnum) + 1; } while (randompoep == DoIt); DoIt = randompoep; document.ImageHolder1.src = images[DoIt].src; } // End --> </script><SCRIPT LANGUAGE="JavaScript"> <!-- Begin var randompoep = 0; var DoIt = 0; images = new Array; images[1] = new Image(); images[1].src = "prod/bpmonitors/bp1.PNG"; images[2] = new Image(); images[2].src = "prod/skaal/sk1.PNG"; images[3] = new Image(); images[3].src = "prod/glucometers/EasyTouchG.PNG"; images[4] = new Image(); images[4].src = "prod/bpmonitors/bp2.PNG"; images[5] = new Image(); images[5].src = "prod/oxygen/2.PNG"; images[6] = new Image(); images[6].src = "prod/glucometers/EasyTouchGC.PNG"; function poeppics() { var imgnum = images.length - 1; do { var randnum = Math.random(); randompoep = Math.round((imgnum - 1) * randnum) + 1; } while (randompoep == DoIt); DoIt = randompoep; document.ImageHolder1.src = images[DoIt].src; } // End --> </script> The only values I changed was: randomTWD to randompoep in the second script code... Hope it can help someone in the future Jaco Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.