title: How to validate an uploaded CSV file if rows are present or not in javascript
body: <p>I have a CSV file which should be validated on uploading in the form. 'Error' should pop up if any rows are missing in the column else it should show 'validated'. I am new to java script and have tried below code but even though rows are not empty the code is showing 'error'. can somebody help me out in identifying where i am going wrong?</p>
  
  <p>The CSV file is as follows:</p>
  
  <pre><code>serial.no.   name
     1         abc
     2         def
  </code></pre>
  
  <p>if any row is missing it should show 'error' else 'validated'</p>
  
  <p>This is my javascript code:</p>
  
  <pre><code>&lt;script&gt;
      function checkfilesize()
      {
          if (document.getElementById("myFile").files[0].size &gt; 100000) // about 8 kb here,20971522 mb for bytes.
          {
              alert("File size must under 10kb!");
          document.getElementById("myFile").value="";
          return;
          }
      }
  
  
  function newDoc()
      {
          var flag = 0;
          var fileUpload = document.getElementById("myFile");
          var reader = new FileReader();
          reader.onload = function (e) 
          {
              var rows = e.target.result.split("\n");
              for (var i = 1; i &lt; rows.length; i++) 
              {
                  var cells = rows[i].split(",");
                  for (var j = 0; j &lt;cells.length; j++) 
                  {
                      if(cells[j]=="")
                      {
                      window.alert("ERROR");
                      flag=1;
                      break; 
                  }
  
              }   
              if(flag==1)
              break;          
              }
              if (flag)
              window.alert("ERROR");
              else
              window.alert("VALIDATED");                                  
          }
          reader.readAsText(fileUpload.files[0]);
      }       
  
  
  &lt;/script&gt;
  </code></pre>