I am trying to load a locally saved video using the form tag and javascript in the browser. It should first be selected and then loaded by pressing the upload button. At the moment I can select and load a video, but it disappears after the function call. I've tried a lot and unfortunately don't know what to do. I would be very happy to get help. Enclosed the complete code. Thank you!
'''
test
<form method="post" enctype="multipart/form-data" id="myForm">
<label>choose a video!
<input name="file" type="file" size="50" accept="video/*" id="file">
</label>
<button id="btn">
Upload
</button>
<output id="dateiListe"></output>
</form>
<video id="my_player" controls="control" width="500" height="300" align="center">
<source type="video/mp4" id="vidsource">
</video>
<script>
document.addEventListener("DOMContentLoaded", function()
{
document.getElementById('myForm').addEventListener('submit', set_source , false);
});
const files = document.getElementById('file').files;
var video = document.getElementById("my_player");
function set_source()
{
video.setAttribute("src", URL.createObjectURL(files[0]));
alert("Upload done");
}
</script>
'''