Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Dec 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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.

    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>

  • #2
    Regular Coder
    Join Date
    Sep 2007
    Location
    AZ, USA
    Posts
    685
    Thanks
    6
    Thanked 46 Times in 46 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •