Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

126
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda