Matchu-petchu
New member
I'm compleatly new to using html/javascript, so I'm not entirely sure if this is working right. Anyway, what I'm trying to do, is make an image from an array appear randomly upon page load. I have in comments how I had it before, just one image displayed after another.
<html>
<body>
<script type = "text/javascript">
alert("script working");
//array of images in file
var image_name = new Array("dir/images/lightbrights/chia.png","dir/images/lightbrights/dna.png","dir/images/lightbrights/face.png", "dir/images/lightbrights/pattern.png","dir/images/lightbrights/pokemon.png","dir/images/lightbrights/rainbow.png");
document.r_img.src = img_name[0];
alert("line passed");
function showImage(){
var length = img_name.length;
var random = Math.floor(length*Math.random());
return img_name[random];
}
</script>
<img src = "showImage()"/>
<!--
<img src = "dir/images/lightbrights/chia.png"/>
<img src = "dir/images/lightbrights/dna.png"/>
<img src = "dir/images/lightbrights/face.png"/>
<img src = "dir/images/lightbrights/pattern.png"/>
<img src = "dir/images/lightbrights/pokemon.png"/>
<img src = "dir/images/lightbrights/rainbow.png"/>
-->
</body>
</html>
I have checked google, and yes, I did kind of come up with results.
Though similar, what I found wasn't exactly what I'm looking for. And I think what I'm looking to do is simpler then the examples on websites...
<html>
<body>
<script type = "text/javascript">
alert("script working");
//array of images in file
var image_name = new Array("dir/images/lightbrights/chia.png","dir/images/lightbrights/dna.png","dir/images/lightbrights/face.png", "dir/images/lightbrights/pattern.png","dir/images/lightbrights/pokemon.png","dir/images/lightbrights/rainbow.png");
document.r_img.src = img_name[0];
alert("line passed");
function showImage(){
var length = img_name.length;
var random = Math.floor(length*Math.random());
return img_name[random];
}
</script>
<img src = "showImage()"/>
<!--
<img src = "dir/images/lightbrights/chia.png"/>
<img src = "dir/images/lightbrights/dna.png"/>
<img src = "dir/images/lightbrights/face.png"/>
<img src = "dir/images/lightbrights/pattern.png"/>
<img src = "dir/images/lightbrights/pokemon.png"/>
<img src = "dir/images/lightbrights/rainbow.png"/>
-->
</body>
</html>
I have checked google, and yes, I did kind of come up with results.
Though similar, what I found wasn't exactly what I'm looking for. And I think what I'm looking to do is simpler then the examples on websites...