Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

fileinput

By: a guest on Mar 18th, 2012  |  syntax: JavaScript  |  size: 1.60 KB  |  hits: 558  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <HTML>
  2. <HEAD>
  3. <!-- Including The jQuery Library -->
  4.                 <script src="http://code.jquery.com/jquery-1.6.3.min.js"></script>
  5.                
  6.         <SCRIPT>
  7.         if (ques = quesraw)
  8.                 ans = ansraw;
  9.        
  10.         function checkAns() {
  11.         var selection = document.multchoice.ans;
  12.         for (i=0; i<selection.length; i++)
  13.                  if (selection[i].checked == true)
  14.                         if (selection[i].value == ansval)
  15.                                 alert("Correct");
  16.                         else
  17.                                 alert("fail");
  18.         }              
  19.                        
  20. document.getElementById('file').addEventListener('change', readFile, false);
  21.  
  22.    function readFile (evt) {
  23.        var files = evt.target.files;
  24.        var file = files[0];          
  25.        var reader = new FileReader();
  26.        reader.onload = function() {
  27.          console.log(this.result);            
  28.        }
  29.        reader.readAsText(file)
  30.     }
  31.  
  32.  
  33.         </SCRIPT>
  34. </HEAD>
  35. <BODY>
  36.  
  37. <input type="file" id="file" />
  38. <script>
  39. document.write(file);
  40. </script>
  41. <div id="text"></div>
  42.         <Div id = "Question">
  43.         <form name="multchoice" method="post">
  44.         <p>This is a statement, but we need a question? </p>
  45.                 <class = "a">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="ans" id="ans1" value="a"/>Wrong <br /></class>
  46.                 <class = "b">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="ans" id="ans2" value="b"/>Wrong  <br /></class>
  47.                 <class = "c">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="ans" id="ans3" value="c"/>Wrong  <br /></class>
  48.                 <class = "d">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="ans" id="ans4" value="d"/>Right <br /></class>
  49.                 <br>
  50.                 <input type="submit" value="Submit" onclick="checkAns()" />
  51.         </form>
  52.         </Div>
  53.  
  54.  
  55.  
  56. </BODY>
  57. </HTML>