Hello I have a select and an input button to browse files, and i would love to save the options in the select to a text file in the format:
line1 line2 line3 ...
I have read this tutorial:
Save <Select >Tag values into text file
But it does not seem to work. When i save, the options are written in the same line and only the first word for the option value is writte to the file. I.E. my options are:
buy food call john print documents
the output in the file is: buy call print
The code i use is:
var textToWrite = "";
$('#todolist>option').each(function () {
textToWrite += this.value + "\n";
});
var textFileAsBlob = new Blob([textToWrite], {type: 'text/plain'});
var fileNameToSaveAs = "directive.txt";
var downloadLink = document.createElement("a");
downloadLink.download = fileNameToSaveAs;
downloadLink.innerHTML = "Download File";
console.log("innerHTML -> " + downloadLink.innerHTML);
window.webkitURL != null;
downloadLink.href = window.webkitURL.createObjectURL(textFileAsBlob);
downloadLink.click();
}
var button = document.getElementById('file-save');
button.addEventListener('click', saveTextAsFile);
I am using google's link for jquery:
Can anybody help? Thanks in advance
So you want also the text, not only the values?
$('#todolist>option').each(function () {
textToWrite += this.value + ":" + this.innerText + "\n";
});