Is it possible to save the data from local storage to a csv file?
First i want to fill in a html form, after that Some pictures are shown with rating buttons. My idea is to store all the input in the local storage and then save all to a csv file (this should be saved on a server) Is there any way to save all the data at the end to a csv file?
Using Blob (https://developer.mozilla.org/en/docs/DOM/Blob) this seems achievable. First generate the file from the local store then blast it off to the server however you like. This should get you going in the right direction:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>CSV Export</title>
<script>
function exportData() {
var item = localStorage.csv=",what you want in the CSV,";
var ary = localStorage.getItem( "csv" ); //csv as a string
var blob = new Blob([ary], {type: "text/csv"});
var url = URL.createObjectURL(blob);
var a = document.querySelector("#results"); // id of the <a> element to render the download link
a.href = url;
a.download = "file.csv";
}
</script>
</head>
<body>
<button onclick="exportData()">Download CSV</button><br>
<a id="results">CSV from local store</a>
</body>
</html>
Getting the file onto the server is another matter but you should be able to tweak this and use PHP, .NET or whatever else.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With