...

View Full Version : Image change and Play sound onclick



needsoftware
04-27-2008, 01:12 AM
Hi, Ive managed to sort out a code with the help of the net. What it does is that when you click the play image it changes to the stop image and plays a sound.

What im having trouble with is stopping the sound when the button is pressed again. I need to keep the function of getting the sound file dynamically.



var tggle='on';
var obj;

window.onload=function() {
obj=document.getElementById('playStop')
document.getElementById('mylink').onclick=function() {
toggle();
return false;
}
}
function toggle(){
if(tggle=='on'){
obj.src="stop.gif";
tggle='off';
}
else {
obj.src="play.gif";
tggle='on';
}
}
function DHTMLSound(surl) {
document.getElementById("dummyspan").innerHTML=
"<embed src='"+surl+"' hidden=true autostart=true loop=false>";
}

<a id="mylink" href="#"><img style="border-style:none;" id="playStop" src="play.gif" alt="" onClick="DHTMLSound('test.wav')"></a>
<span id=dummyspan></span>

binaryWeapon
04-28-2008, 12:00 AM
How about when you click to stop it, document.getElementById("dummyspan").innerHTML=""? If that doesn't work, you could try having an empty sound file the you could choose to play, like so: document.getElementById("dummyspan").innerHTML=
"<embed src='emptySound.wav' hidden=true autostart=true loop=false>";



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum