Call random images

I’m trying to create a script to call 5 random images for a “captcha type thing”

this is the code I have

function showImg() {

					var imgNumber = randomInteger(9); 
					
					document.write('<img src=" + imgNumber + " alt="" />');

					}

That is in the

function randomInteger(size) {
return Math.floor((size+1)*Math.random());
}

That is in an external file

		   	<script type="text/javascript">
				showImg();
				showImg();
				showImg();
				showImg();
				showImg();
			</script>

           </td>

And then that is where I want to call that function 5 time to produce 5 random images

What am I missing?

hello mdahlke,

i have checked your code and modify this use below code it will work for you.

Note: add correct path to imag src attribute.
for below script put images and script in same folder and run the code.

[php]

SR Logic function showImg() { var imgNumber = randomInteger(9);
			document.write('<img src="' + imgNumber + '" alt="" />');
		}
		function randomInteger(size) {
		   var x = Math.floor((size+1)*Math.random());
		   return x+'.jpg';
		}
	</script>
</body>
	<td colspan="2" class="center">
		 <script type="text/javascript">
		 	showImg();
		 	showImg();
		 	showImg();
		 	showImg();
		 	showImg();
		 </script>
	</td>

[/php]

i hope this will helpful for you…
SR

that worked perfectly, Thank you

Sponsor our Newsletter | Privacy Policy | Terms of Service