0

So currently I have an HTML page where the user completes some data entry. Their data is spanned into a form on the page which they then copy and paste into a text file. I would like to include a button that would simply take the form, along with the spanned data, and save it to a text file. This will all be done locally, the user will have the HTML file saved on their computer. I have tried doing this via a textarea and a div but in both cases the text file doesn't include the actual user data but just the HTML code. Here as example of how the program works:

function example(){
   var elements = document.querySelectorAll(".showexample");
   for(var i = 0; i<elements.length; i++){
      elements[i].innerHTML = document.querySelector(".exampleinput").value;
   }
}

<TD><input type="text" class="exampleinput" oninput="example()"></TD>

<div id="forUserDownload">
your input:<span class='showexample'></span>
</div>

When I try to include a download function (such as the one here:https://thiscouldbebetter.wordpress.com/2012/12/18/loading-editing-and-saving-a-text-file-in-html5-using-javascrip/), it just shows the HTML code instead of the actual user input. Is there anyway to do this with only HTML and Javascript?

  • Unfortunately this solution is the same as the one I tried previously. The text area does not span the data the user entered. – SammyfromIT Apr 18 '22 at 01:58
  • Can you supply the code, you've tried already, to create and save the file? – Pellay Apr 18 '22 at 02:09
  • I think this question should be opened again. The duplicate that is linked to is not really answering the question in a good way. The closest answer in my opinion is https://stackoverflow.com/a/20194533/322084 but the content type in the example should be changed to text/plain and it also needs to be wrapped in an callback for the input event. – chrwahl Apr 18 '22 at 08:22

0 Answers0