I'm trying to save the contents of a textarea in a file. The problem is that the code below creates a file but the file's name is the content of the textarea. It should be myfile.txt.
This code seems to be the problem.
But in the examples online, some coders use just one variable (filename) and some use two (filename, content). So I'm stuck and could use some help. Thanks.
JavaScript:
<script>
document.getElementById("mybutton").addEventListener("click", buttonclick);
function buttonclick(data, filename, type) {
var filename = "myfile".txt"
var content = document.getElementById("mytext").value;
var file = new Blob([content], {type: type});
var a = document.createElement("a")
url = URL.createObjectURL(file);
a.href = url;
a.download =(filename, content);
document.body.appendChild(a);
a.click();
setTimeout(function() {
document.body.removeChild(a);
window.URL.revokeObjectURL(url);
}, 0);
}
</script>
JavaScript:
a.download =(filename, content);