Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

132
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda