How to save a textarea as a text file

606 Views Asked by At

im trying to make my own software similar to microsoft word just with html. basically i have a textarea and they enter the text and save it. problem is, when I saved it to my computer to test it out everytime it reset the textarea. i had a button that did a javascript alert box telling the to press "CTRL+S" to save the file, but as i said i resets the textarea. is there a differnt tag other than the textarea tag, or do i just need a differnt method of savind the file. If you have any code suggestions please share it with me, thanks! here is my code:

 textarea {
    background-color: #E6E6E6;
    }
     </style>
</head>
<body>
    <div class="container">
        <div class="jumbotron">

            </h1>
            </div>
        </div>
        </div>


        <button onclick="myFunction()">
              <noscript>
                <b> Press CTRL+S And Name It Something (---------).html </b>
            </noscript>Save
        </button>



        <script>
      function myFunction() {
      alert("To Save Press CTRL+S And Name It Something (---------).html ");
      }
        </script>
1

There are 1 best solutions below

0
On

If you press CTRL+S in a browser window, the browser will save the original html which came from the server (here your local computer). In this case the html itself does not contain the text, so it's not saved.

If you'd like to save the entered text, you'll have to make a separate function to include the textarea content in the html.