I have tried using both \n and \r\n however, the exported file does not contain the line break. Any idea what I am missing?
I would like the text to return as:
indexname_text
indextype_text
Below is my code
<!-- Button to download -->
<button type="button" class="button" id="dwn-btn" style="vertical-align:middle">Download as .bat file</button>
document.getElementById("dwn-btn").addEventListener("click", function () {
var copyIndexNameField = document.getElementById("indexName");
var copyIndexName = document.getElementById("indexName");
var copyIndexTypeField = document.getElementById("IndexTypeCheckBox");
var copyIndexType = document.getElementById("IndexTypeTextBox");
var output = document.getElementById("output");
if (copyIndexNameField.value) {
indexname_text += "--index-name " + copyIndexName.value + " ";
}
if (copyIndexTypeField.checked) {
indextype_text += "--index-type " + copyIndexType.value;
}
output.value =
+ indexname_text
+ "\n"
+ indextype_text;
var text = document.getElementById("output").value;
var filename = "export.bat";
download(filename, text);
function download(filename, text) {
var element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
` for a line break. – geocodezip Nov 24 '20 at 21:51
does not work. – Ted Lin Nov 25 '20 at 14:54
` or `\n` or `\r` will work there. You might need to make it a ` – geocodezip Nov 25 '20 at 15:37