Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-27-2008, 12:12 AM   PM User | #1
needsoftware
New to the CF scene

 
Join Date: Dec 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
needsoftware is an unknown quantity at this point
Smile Image change and Play sound onclick

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.

Quote:
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>
needsoftware is offline   Reply With Quote
Old 04-27-2008, 11:00 PM   PM User | #2
binaryWeapon
Regular Coder

 
Join Date: Sep 2007
Location: AZ, USA
Posts: 685
Thanks: 6
Thanked 46 Times in 46 Posts
binaryWeapon is on a distinguished road
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>";

Last edited by binaryWeapon; 04-27-2008 at 11:01 PM.. Reason: icode
binaryWeapon is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:08 AM.


Advertisement
Log in to turn off these ads.