Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
- <meta content="utf-8" http-equiv="encoding">
- <html>
- <head></title>Save Text as File</title>
- <script type='text/javascript'>
- function handleFileSelect() {
- if (!window.File || !window.FileReader || !window.FileList || !window.Blob) {
- alert('The File APIs are not fully supported in this browser.');
- return;
- }
- input = document.getElementById('fileinput');
- if (!input) {
- alert("Um, couldn't find the fileinput element.");
- }
- else if (!input.files) {
- alert("This browser doesn't seem to support the `files` property of file inputs.");
- }
- else if (!input.files[0]) {
- alert("Please select a file before clicking 'Load'");
- }
- else {
- file = input.files[0];
- fr = new FileReader();
- fr.onload = receivedText;
- fr.readAsText(file);
- // fr.readAsDataURL(file);
- }
- }
- function receivedText() {
- //result = fr.result;
- console.log(fr.result);
- var arr = fr.result.split('\n');
- for (var i = 0; i < arr.length; i++){
- // document.getElementById('editor' + i).appendChild(document.createTextNode(arr[i]));
- editor.appendChild(document.createTextNode(arr[i]));
- editor.appendChild(document.createElement("br"))
- getOrientationCheck(i)
- getSelectCheck(i)
- }
- }
- function getOrientationCheck(i){
- orientation.appendChild(getCheckBox(i));
- orientation.appendChild(document.createElement("br"))
- }
- function getSelectCheck(i){
- select.appendChild(getCheckBox(i));
- select.appendChild(document.createElement("br"))
- }
- function getCheckBox(i){
- var checkbox = document.createElement("input");
- checkbox.type = "checkbox"; // make the element a checkbox
- checkbox.name = "checkbox" + i; // give it a name we can check on the server side
- checkbox.value = "checked"; // make its value "pair"
- return checkbox
- }
- </script>
- </head>
- <body>
- <input type="file" id="fileinput"/>
- <input type='button' id='btnLoad' value='Load' onclick='handleFileSelect();'>
- <table>
- <tr>
- <td> <div id="editor"></div> </td>
- <td> <div id="orientation"></div> </td>
- <td> <div id="select"></div> </td>
- </tr>
- </table>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement