PDA

View Full Version : help toggling sound with on/off img buttons



moscarda
02-07-2009, 04:49 AM
the below code is working, i just need help with the music. when the button is clicked, i want it to play loop.mp3 and when it is clicked again I want it to stop. personally, i always have trouble with embedding sound with javascript, especially adding it to other functions going on. sorry for the newbie question, but thanks in advance.



<script language="javascript">
function toggle() {
var ele = document.getElementById("toggleText");
var text = document.getElementById("displayText");
if(ele.style.display == "block") {
ele.style.display = "none";
text.innerHTML = "<img src='paused.gif' border='0'>";
}
else {
ele.style.display = "block";
text.innerHTML = "<img src='system/playing.gif' border='0'>";
}
}
</script>

<a id="displayText" href="javascript:toggle();"><img src="paused.gif" border='0'></a>
<div id="toggleText" style="display: none"><h1>sound should play now</h1></div>

jscheuer1
02-07-2009, 04:29 PM
Flash is a better choice for this. But if you want to use HTML and javascript, see:

http://loisimages.com/john/music/music_adv_dd.htm

Use your browser's 'view source' to get the code.