Tell me how to organize the unloading of selected value values ​​to a file, with the sequence 111 or 001. I explain:
0 this is a1
1 is b2
After I select the result of my actions in the span tag, I have practically no experience with working with files, tell me how to save the received data to a txt file for example.

function recalculate(){ $('#res').text(''); var sum = 0; $('div').each(function(){ var selectVal = $('select',this).val(); $('#res').append(selectVal); if($(this).index() < $('div').length - 1){ $('#res').append(' '); -- получаю value значения выбранных селектов, проблема в сохранении. Подскажите как реализовать } sum +=selectVal * 1; }); $('#res').append('<p>Согласовано: ' + sum + ' </p>'); return; } $('select').change(function(){ recalculate(); }); 

Example

I am writing only on js or jQuery. Php in this work do not consider.

  • js does not work with files, you need the server part, do it on nodejs for example - Vasily Barbashev
  • and tell me where to start the article or where to start, I am not at all familiar with nodejs. - Eliot
  • apparently misunderstood you, you need to process on the server or just download the user, if the latter, then the option proposed in the answer will suit you. If it's the first one, there is a lot of documentation on working with files and creating a simple server, you can look towards Express on nodejs - Vasily Barbashev
  • 2 option, the user chose the values ​​of selekt, and the file on the client would save the txt file with the text inside 111 for example. - Eliot
  • Use the method from the bottom, generate data for example var data = 'Hello from App' , and call the download(data, 'customFileName', 'text') method download(data, 'customFileName', 'text') , you will download the file with the text Hello from App and the file name will be customFileName - Vasily Barbashev

1 answer 1

 // Function to download data to a file function download(data, filename, type) { var a = document.createElement("a"), file = new Blob([data], {type: type}); if (window.navigator.msSaveOrOpenBlob) // IE10+ window.navigator.msSaveOrOpenBlob(file, filename); else { // Others var url = URL.createObjectURL(file); a.href = url; a.download = filename; document.body.appendChild(a); a.click(); setTimeout(function() { document.body.removeChild(a); window.URL.revokeObjectURL(url); }, 0); } } 

Such a thread on SO.com took about 2 seconds of googling.