Inputs value of a form

0

I'm developing a form with javascript / jquery in which from one question to another it goes to another page and on the last page I have to see all the data typed in the previous questions, I've already tried with serializearray (), but it just catches the data from the last page, I would like to know if you have any other method or even with serializearray.

    
asked by anonymous 08.05.2018 / 21:04

2 answers

1

You can use localStorage as you said!

For example, I did this Codepen to help you!

Here are two very good articles to understand how localStorage works:

Article 1

Article 2

    
08.05.2018 / 21:48
1

Dude, I'll give you a basic example here and hope it helps.

Page you get the value to transfer to another page:

<input type="text" id="texto">
<a href="mostraDados.html"><button type="button" onclick="setaValor()">Pegar</button></a>

<script>
    function setaValor() {
        var texto = document.getElementById('texto');
        var textoValor = texto.value;
        var textoStorage = window.localStorage.setItem('valorTexto', textoValor);
    }
</script>

<style>
    input { border: solid 1px #ccc; border-radius: 2px; height: 20px; }
    button { border: solid 1px #ccc; border-radius: 2px; height: 30px; cursor: pointer;}
</style>

Page that receives the page with the value of the previous page:

<input type="text" id="recebeTexto"> Valor trazido da página anterior 
<br><br>
<a href="setaDados.html"><button type="button">Voltar</button></a>

<script>
    function mostraValor() {
        var textoRecebido = window.localStorage.getItem('valorTexto');      
        document.getElementById('recebeTexto').value = textoRecebido;           
    }   

    window.onload = function() {
        mostraValor();
    };
</script>

<style>
    input { border: solid 1px red; border-radius: 2px; height: 20px; }
    button { border: solid 1px #ccc; border-radius: 2px; height: 30px; cursor: pointer;}
</style>
    
08.05.2018 / 21:50