Error trying to use HTML5 Local Storage

0

I am studying about local storage in HTML5 and JS, understanding that its purpose is to store texts in local / p>

When testing, I got JS errors. I would like to understand why:

<scripttype="text/javascript">

function exibir(){
    document.getElementById("nome").value = localStorage.getItem("l_nome");
}

</script>
<body onload="exibir();">
    <form>
        Nome: <input type="text" id="nome">
        <input type="button" onclick="salvar();" value="Save">
    </form>
</body>
    
asked by anonymous 23.09.2014 / 19:37

1 answer

5

You just needed to set the SAVE function:

<script type="text/javascript">

function exibir(){
    document.getElementById("nome").value = localStorage.getItem("l_nome");
}

function salvar(){
    localStorage.setItem("l_nome", document.getElementById("nome").value);
}

</script>
<body onload="exibir();">
    <form>
        Nome: <input type="text" id="nome">
        <input type="button" onclick="salvar();" value="Save">
    </form>
</body>
    
23.09.2014 / 21:18