I'm doing something funny on a page. I've got it so when you click a link it plays a sound. Using this code in the head <script language="javascript" type="text/javascript"> function playSound(soundfile) { document.getElementById("dummy").innerHTML= "<embed src=\""+soundfile+"\" hidden=\"true\" autostart=\"true\" loop=\"false\" />"; } </script> Code (markup): a dummy span on the page <span id="dummy"></span> Code (markup): and this to call it <a href="#" onclick="playSound('path to soundfile');">Click here</a> Code (markup): So far so good. Now I would like to make play a random sound.
Put the file paths in an array, generate a random number that points to an index in the array and play that. var paths = new Array('path1', 'path2', 'path3'); function playRandom () { var index = Math.floor(Math.random() * paths.length); playSound(paths[index]); } Code (markup): And change your onclick event to call playRandom().
Thanks I knew it would be something like that. I'll pm a link when it is working later. It's kinda funny.