Reputation: 87
I have not much experience in javascript. I have one function in javascript is like below
function createDownloadLink(blob) {
var url = URL.createObjectURL(blob);
var au = document.createElement('audio');
var li = document.createElement('li');
var link = document.createElement('a');
//name of .wav file to use during upload and download (without extendion)
var filename = new Date().toISOString();
//add controls to the <audio> element
au.controls = true;
au.src = url;
//save to disk link
//add the new audio element to li
li.appendChild(au);
//upload link
var upload = document.createElement('a');
upload.classList.add('mybutton');
upload.href="#";
upload.innerHTML = "Upload";
upload.addEventListener("click", function(event){
var xhr=new XMLHttpRequest();
xhr.onload=function(e) {
if(this.readyState === 4) {
console.log("Server returned: ",e.target.responseText);
}
};
var fd=new FormData();
fd.append("audio_data",blob, filename);
xhr.open("POST","upload.php",true);
xhr.send(fd);
})
li.appendChild(document.createTextNode (" "))//add a space in between
li.appendChild(upload)//add the upload link to li
//add the li element to the ol
recordingsList.appendChild(li);
}
Its create recording list on press Stop Button. Instead I want discard if there old list and show only last one. Means I do not need multiple list, Instead I want only single one.
Current list looking like below image.
Let me know if anyone here can help me for achieve my goal. Thanks!
Upvotes: 0
Views: 84
Reputation: 763
Remove the old ones before you add the new one.
// Clear all previous recordings and add the new one
recordingsList.innerHTML = '';
recordingsList.appendChild(li);
Upvotes: 1