samedi 5 novembre 2016

Play audio when checkbox is checked with javascript

I'm trying to make a short audio file play when a html checkbox is checked. I'm probably missing something elementary. Here is my code:

<body>
    <input type="checkbox" id="cena" onchange="myfunction()"></input><label for="cena"></label>
</label><script>
function myfunction(){
var audio = new audio('rusbtaudio.mp3');
audio.play();
}
</script>
    </body>

rusbtaudio.mp3 is in same folder as html file.




Aucun commentaire:

Enregistrer un commentaire