Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

124
Views
Save options from a select to file with JS

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

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

So you want also the text, not only the values?

$('#todolist>option').each(function () {
    textToWrite += this.value + ":" + this.innerText + "\n";
});
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!