How to save <textarea> in HTML?

Asked

Viewed 815 times

-5

When I run javascript, it runs normally, my doubt was, like I get the code now from this table that the script changed.

  • You want to save the text typed in the textarea where? only html I believe is not possible. At least you will need javascript, even I do not believe it is possible to save data in the machine direct javascript.

  • Save where? ..

  • 1

    I have this html ae, only saved on my pc. I open it in my browser, as I put the save button to it save in my pc html.

  • What HTML on your PC?

  • <html> <table><textarea>Tester</textarea></table> </html>

  • You want to make a button to save or just put this text in the textarea?

  • Save where? That’s the question!

  • To save the typed content in the textarea you must first place it in a form and submit the submission through an input type Submit, as a reading suggestion I recommend the following link: http://tableless.com.br/formulario-basic-in-8-minute/. About how to save is relative, you want to do save in a txt file, database...?

  • maybe he wants to use something like HTML5’s Storage site http://www.w3schools.com/html/html5_webstorage.asp

  • just put this text in the textarea

Show 5 more comments

1 answer

3

Using the Local Storage of HTML5 you can save textarea text locally, so even though you close the file the values will be there.

Code:

<!DOCTYPE html>
<html>
    <body>

    <html><table><textarea id='result'>Escreva aqui seu lembrete</textarea></table></html>
    <button onClick="salvar()">Salvar</button>

    <script>

    function salvar() {
        // Check browser support
        if (typeof(Storage) !== "undefined") {
            // Store
            localStorage.setItem("text", document.getElementById("result").value);

        } else {
            document.getElementById("result").innerHTML = "Local Storage não suportado";
        }
    }

    // Retrieve
        document.getElementById("result").innerHTML = localStorage.getItem("text");
    </script>

    </body>
</html>

JS Fiddle: https://jsfiddle.net/5ndnu2nn/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.