Created
November 15, 2024 10:05
-
-
Save mtsmfm/fa27a9819cab93a5fefc7590ecc4a151 to your computer and use it in GitHub Desktop.
file upload with elem.click
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>File upload</title> | |
</head> | |
<body> | |
<input id="file" type="file" hidden onchange="onFileAttached()" /> | |
<button id="button" onclick="uploadFile()">Upload</button> | |
<div id="filename"></div> | |
</body> | |
<script> | |
const button = document.getElementById("button") | |
button.onclick = () => { | |
const fileElem = document.getElementById("file") | |
fileElem.click() | |
} | |
const file = document.getElementById("file") | |
file.onchange = (event) => { | |
const file = event.target.files[0] | |
const filename = document.getElementById("filename") | |
filename.innerText = file.name | |
} | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment