title: Applying javascript to check file size and extension
body: <p>here is my script. What I am trying to do is to trigger it using onchange event.
  But it seems does not work very well. I have tried edit here and there but still facing problems. As for my latest edit below, the problem is, there is 2 files to be uploaded, but only the second one will display alert message, while the first one will just receive any file.</p>
  
  <pre><code>    &lt;script&gt;
      function checkFile()
      {   
      var node_list = document.getElementsByTagName('input');
      for (var i = 0; i &lt; node_list.length; i++) 
      {
          var node = node_list[i];
          if (node.getAttribute('type') == 'file') 
          {
              var sFileName = node.value;
              var sFileExtension = sFileName.split('.')[sFileName.split('.').length - 1];
              var iFileSize = node.files[0].size;
              var iConvert=(node.files[0].size/10485760).toFixed(2);
          }
  
  
          if (sFileExtension != "pdf" &amp;&amp; sFileExtension != "doc" &amp;&amp; sFileExtension != "docx" &amp;&amp; iFileSize&gt;10485760)
          {   
              txt="File type : "+ sFileExtension+"\n\n";
              txt+="Size: " + iConvert + " MB \n\n";
              txt+="Please make sure your file is in pdf or doc format and less than 10 MB.\n\n";
              alert(txt);
          }
      }
  }
      &lt;/script&gt;
  </code></pre>
  
  <p>my form,</p>
  
  <pre><code>  &lt;input type="file" name="file" id="confirm" onchange="checkFile()"&gt;
    &lt;input type="file" name="file" id="approveletter" onchange="checkFile()"&gt;
  </code></pre>