M
meagain
I've used javascript to generate a random number,
but can you tell me how to choose a random "img"?
but can you tell me how to choose a random "img"?
I've used javascript to generate a random number,
but can you tell me how to choose a random "img"?
I've used javascript to generate a random number,
but can you tell me how to choose a random "img"?
I've used javascript to generate a random number,
but can you tell me how to choose a random "img"?
fairly simple to do in PHP.
create an array with img names.
then use the random function to select one.
show the img.
123Jim said:This looks quite good: http://www.dyn-web.com/code/basics/random_image/random_img_js.php
Not tested by myself however.
I've used javascript to generate a random number,
but can you tell me how to choose a random "img"?
or in xhtml thus:
<img id="randomImage1"> <---- this
I've used javascript to generate a random number,
but can you tell me how to choose a random "img"?
The following is one way to do so in javascript, as you said you've used
javascript, but I actually have no idea whether you want to use javascript
for this or not .....
your javascript example looks well -
but isn't it much more easy (in case there is a relation:
"random number"~"number of pics")
to use document.writeln(... and here you use the random number to write
the number of the gif (.jpg, whatever)?
Yes, you can do it that way, but working through the DOM seems to be
generally considered as better practice than document.write/ln, and
provides a method that can be used to, for example, change the random
image to another one when it is clicked on. I'm not sure that's so easy
to do with document.write/ln
http://www.sined.co.uk/tmp/randomimg2.htm
Note that sometimes it will choose the current image as the new random
image, so if it doesn't change when you click it, just click it again.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.