Detecting when audio is finished playing using javascript.?

I am playing audio file using javascript,How will I check audio complete.?
I wrote js function but it is not working.

var myAudio = document.getElementById("myAudio");
	myAudio.play();

 myAudio.addEventListener('ended', function() {
this.currentTime = 0;
alert("ended");

}, false);

Please help me,How will I check.?

Do you have more information? or a document because the code looks ok.

Thank You Dbear,
There was some error in my code,Javascript code is working…