You could do it with custom made
ASP Sub Function or the JavaScript Array function!
JavaScript Array Function:
Code:
<head>
<script language="JavaScript">
<!-- Hide from old browsers
var imagenumber = 6 ;
var randomnumber = Math.random() ;
var rand1 = Math.round( (imagenumber-1) * randomnumber) + 1 ;
images = new Array
images[1] = "img/pic1.jpg"
images[2] = "img/pic2.jpg"
images[3] = "img/pic3.jpg"
images[4] = "img/pic4.jpg"
images[5] = "img/pic5.jpg"
images[6] = "img/pic6.jpg"
var image = images[rand1]
// -- End Hiding Here -->
</script>
</head>
..
..
<body>
<script language="JavaScript">
// <-- Hide this script from old browsers --
document.write('<IMG SRC="' + image + '">')
// -- End Hiding Here -->
</script>
</body>
ASP Sub Function:
<%
Sub Random_pic()
Dim Pics
Randomize
Pics=Int(Rnd()* 7)
Select Case Pics
Case "0"
Response.write ("img/rdm1.gif")
Case "1"
Response.write ("img/rdm2.gif")
Case "2"
Response.write ("img/rdm3.gif")
Case "3"
Response.write ("img/rdm4.gif")
Case "4"
Response.write ("img/rdm8.gif")
Case "5"
Response.write ("img/rdm6.gif")
Case "6"
Response.write ("img/rdm7.gif")
End Select
End Sub
%>
'Call the sub function using the img tag!
<img src="<%Random_pic()%>">
Or, if you want less code, you can use this trick!
First Step:
Give your image a constant name like this:- img/image_1.jpg
- img/image_2.jpg
- img/image_3.jpg
- img/image_4.jpg
- img/image_5.jpg
- img/image_6.jpg
- img/image_7.jpg
- img/image_8.jpg
Second Step:
Use the ASP Rnd Function inside your img tag like this:
<img src="img/header_<%=Int(Rnd()* 7)%>.jpg">
This code: <%=Int(Rnd()* 7)%> will generate a random number from 0-7
So the <img src="img/header_RandomNumberGeneratedHere"> will display the image according to the name!
Cool huh?
Cheers...