0

Is there a way to make a function RandomSwapDown(x) randomly so that it shows one of the three images every time you click on it? Thank you.

<script>
    function RandomSwapDown(x) {                 
        x.src = '4.gif';    
    }                               
    function SwapBack(x) {       
        x.src = 'mouse_over.png';           
    }
    function SwapOut(x) {
        x.src = 'mouse_normal.png';
    }  
</script>

</html>

<div style='top: 200px; left: 175px; position: absolute;'>

<img src='mouse_normal.png'  onMouseOver='SwapBack(this)' onMouseOut= 'SwapOut(this)' onMouseDown = 'RandomSwapDown(this)' width="121" height="146" >

<img src='mouse_normal.png'  onMouseOver='SwapBack(this)' onMouseOut= 'SwapOut(this)' onMouseDown = 'RandomSwapDown(this)' width="121" height="146" >

<img src='mouse_normal.png'  onMouseOver='SwapBack(this)' onMouseOut= 'SwapOut(this)' onMouseDown = 'RandomSwapDown(this)' width="121" height="146" >

</div>
user353gre3
  • 2,747
  • 4
  • 24
  • 27

2 Answers2

0

DEMO

var picArr = []; // array of images to choose from

function RandomSwapDown(x) {
    x.src = picArr[Math.floor(Math.random()*3)];
}
function SwapBack(x) {
    x.src = picArr[Math.floor(Math.random()*3)];
}
function SwapOut(x) {
    x.src = picArr[Math.floor(Math.random()*3)];
}
kei
  • 20,157
  • 2
  • 35
  • 62
0

hi i don't now you can use this in javascript but in java you can

Random generator=new Random();    
int rnd_number;    
rnd_number=generator.nextInt(MaxRandom-MinRandom)+MinRandom;
arturomp
  • 28,790
  • 10
  • 43
  • 72
max
  • 5,963
  • 12
  • 49
  • 80