title: Importing CSV data into HTML form
body: <p>I need to import data from csv file into form. I tried example from this topic:</p>
  
  <p><a href="https://stackoverflow.com/questions/33042591/how-to-import-csv-file-into-html-form-and-export-html-form-to-csv-file/33042738">How to import CSV file into HTML form, and export HTML form to CSV file</a></p>
  
  <p>Unfortunately it does not work for me. The file is opening, but no data are put into form.</p>
  
  <p>My index.html file looks as follows:</p>
  
  <pre><code>&lt;html lang="en"&gt;
    &lt;head&gt;
      &lt;meta charset="utf-8"&gt;
      &lt;script type="text/javascript" language="JavaScript" src="script.js"&gt;&lt;/script&gt;
      &lt;script src="https://d3js.org/d3.v3.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;  
  &lt;input id="upload" type="file"&gt;
  
  &lt;form id="csvForm"&gt;
      &lt;input id="a"&gt;&lt;/input&gt;
      &lt;input id="b"&gt;&lt;/input&gt;
      &lt;input id="c"&gt;&lt;/input&gt;
      &lt;input id="d"&gt;&lt;/input&gt;
  &lt;/form&gt;
  &lt;button id="download"&gt;Download&lt;/button&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>And script.js file:</p>
  
  <pre><code>document.getElementById("upload").addEventListener("change", upload, false);
  document.getElementById("download").addEventListener("click", download, false);
  
  function upload(e) {
  
      var data = null;
      var file = e.target.files[0];
  
      var reader = new FileReader();
      reader.readAsText(file);
      reader.onload = function (event) {
          var csvData = event.target.result;
  
          var parsedCSV = d3.csv.parseRows(csvData);
  
          parsedCSV.forEach(function (d, i) {
              if (i == 0) return true; // skip the header
              document.getElementById(d[0]).value = d[1];
          });
  
      }
  }
  
  function download(e) {
  
      data = [["id","value"]];
  
      var f = d3.selectAll("#csvForm &gt; input")[0];
  
      f.forEach(function(d,i){
          data.push([d.id, d.value]);
      });
  
      console.log(data);
  
      var csvContent = "data:text/csv;charset=utf-8,";
      data.forEach(function (d, i) {
          dataString = d.join(",");
          csvContent += i &lt; data.length ? dataString + "\n" : dataString;
      });
  
      var encodedUri = encodeURI(csvContent);
      var link = document.createElement("a");
      link.setAttribute("href", encodedUri);
      link.setAttribute("download", "FormData.csv");
      link.click(); 
  }
  </code></pre>
  
  <p>Shall I add something more? Any other library or framework?</p>
  
  <p>Thank you for any replies.</p>