Advertisement
Guest User

Untitled

a guest
Dec 21st, 2014
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.67 KB | None | 0 0
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
  3. <meta content="utf-8" http-equiv="encoding">
  4. <html>
  5. <head></title>Save Text as File</title>
  6.     <script type='text/javascript'>
  7. function handleFileSelect() {
  8.                 if (!window.File || !window.FileReader || !window.FileList || !window.Blob) {
  9.                     alert('The File APIs are not fully supported in this browser.');
  10.                     return;
  11.                 }
  12.  
  13.                 input = document.getElementById('fileinput');
  14.                 if (!input) {
  15.                   alert("Um, couldn't find the fileinput element.");
  16.                }
  17.                else if (!input.files) {
  18.                   alert("This browser doesn't seem to support the `files` property of file inputs.");
  19.                }
  20.                else if (!input.files[0]) {
  21.                   alert("Please select a file before clicking 'Load'");
  22.                }
  23.                else {
  24.                   file = input.files[0];
  25.                   fr = new FileReader();
  26.                   fr.onload = receivedText;
  27.                   fr.readAsText(file);
  28.                   // fr.readAsDataURL(file);
  29.                }
  30.             }
  31.  
  32. function receivedText() {
  33.    //result = fr.result;
  34.    console.log(fr.result);
  35.    var arr = fr.result.split('\n');
  36.    for (var i = 0; i < arr.length; i++){
  37.   //   document.getElementById('editor' + i).appendChild(document.createTextNode(arr[i]));
  38.        editor.appendChild(document.createTextNode(arr[i]));
  39.        editor.appendChild(document.createElement("br"))
  40.         getOrientationCheck(i)
  41.         getSelectCheck(i)
  42.    }
  43. }
  44.  
  45. function getOrientationCheck(i){
  46.     orientation.appendChild(getCheckBox(i));
  47.    orientation.appendChild(document.createElement("br"))
  48. }
  49.  
  50. function getSelectCheck(i){
  51.     select.appendChild(getCheckBox(i));
  52.    select.appendChild(document.createElement("br"))
  53. }
  54.  
  55. function getCheckBox(i){
  56.     var checkbox = document.createElement("input");
  57.     checkbox.type = "checkbox";    // make the element a checkbox
  58.     checkbox.name = "checkbox" + i;      // give it a name we can check on the server side
  59.     checkbox.value = "checked";         // make its value "pair"
  60.     return checkbox
  61. }
  62.  
  63.  
  64.    </script>
  65. </head>
  66. <body>
  67.  
  68. <input type="file" id="fileinput"/>
  69.         <input type='button' id='btnLoad' value='Load' onclick='handleFileSelect();'>
  70.         <table>
  71.         <tr>
  72.               <td>        <div id="editor"></div> </td>
  73.               <td>        <div id="orientation"></div> </td>
  74.               <td>        <div id="select"></div> </td>
  75.         </tr>
  76.         </table>
  77. </body>
  78.  
  79.  
  80. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement