I want to read a text file content in my computer into a variable using HTML/JAVASCRIPT "Choose a file" using accept=" text/plain".And print the variable value ie content of a file on screen and I also have need in using the variable for other purposes. Ie The following code is not producing output, the contents of the file is not getting transferred to the variable b during b=fa(event);.Can somebody help me in transforming the below code ?
<html>
<body>
<form name="prototype"   action="pro.html"  method="post">
<input type='file'  accept='text/plain' ><br>
<input type="submit" onsubmit="pass()" value="submit" />
<div id='output'>
</form>
 <script>
 function pass()
 {
 var b;
 b=fa(event);
 document.write("\n  <br> <br> Contents=   ",b);
 }
 function fa(event) {
    var input = event.target;
    var reader = new FileReader();
    var a;
    reader.onload = function(){
    var text = reader.result;
    var node = document.getElementById('output');
    node.innerText = text;
    a=reader.result.substring(0, 200);
    return a;
    }
    reader.readAsText(input.files[0]);
     } 
     </script>
     </body>
      </html>
 
     
     
    